我有很多表单(隐藏),我需要用一个按钮关闭它们,但由于某种原因它开始抛出错误“收集被修改;枚举操作可能无法执行”
"System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.Collections.ArrayList.ArrayListEnumeratorSimple.MoveNext()
at System.Windows.Forms.Application.ExitInternal()
at System.Windows.Forms.Application.Exit(CancelEventArgs e)
at System.Windows.Forms.Application.Exit()
..."
代码
this->button1->Click += gcnew System::EventHandler(this, &Outro::button1_Click);
...
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
Application::Exit();
}
答案 0 :(得分:0)
这是一个错误告诉您,您正在从2个或更多线程访问集合而没有锁定保护。
查看CallStack并查看正在访问的集合 该错误表明ArrayList在该线程中被迭代时发生了不同的变化。