I have a lot of forms (hidden) and i need to close them all with a button, but for some reason it started to throw errors "Collection was modified; enumeration operation may not execute"
"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()
..."
Code
this->button1->Click += gcnew System::EventHandler(this, &Outro::button1_Click);
...
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
Application::Exit();
}