gpt4 book ai didi

c# - 集合被修改;枚举操作可能无法执行。 C#

转载 作者:行者123 更新时间:2023-11-30 18:51:50 25 4
gpt4 key购买 nike

<分区>

我需要帮助。我正在使用数组列表,突然出现此错误。

An unhandled exception of type 'System.InvalidOperationException' occurred in mscorlib.dll

Additional information: Collection was modified; enumeration operation may not execute.

这是显示异常的代码...

foreach (PC_list x in onlinelist) {
if ((nowtime.Subtract(x.time)).TotalSeconds > 5) {
Invoke(new MethodInvoker(delegate {
index = Main_ListBox.FindString(x.PcName);
if(index != ListBox.NoMatches)
Main_ListBox.Items.RemoveAt(index);
}));
onlinelist.Remove(x);
//Thread.Sleep(500);
}
}

在哪里

public class PC_list {
public string PcName;
public string ip;
public string status;
public string NickName;
public DateTime time;

}

注释:

  • onlinelist 是一个数组列表
  • nowtime 和 x.time 是日期时间。

调用栈

mscorlib.dll!System.Collections.ArrayList.ArrayListEnumeratorSimple.MoveNext() + 0x122 bytes    
BlueBall.exe!BlueBall.BlueBall.clean_arraylist() Line 74 + 0x1a8 bytes C#
BlueBall.exe!BlueBall.BlueBall.server() Line 61 + 0x8 bytes C#
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state) + 0x63 bytes
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool ignoreSyncCtx) + 0xb0 bytes
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x2c bytes
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() + 0x44 bytes
[Native to Managed Transition]

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com