System.InvalidOperationException由于随叫随到收集修改Application.Exit() [英] System.InvalidOperationException due to collection modification on call to Application.Exit()

查看:328
本文介绍了System.InvalidOperationException由于随叫随到收集修改Application.Exit()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这真的,真的很奇怪的错误,我从来没有能够牵制(这很少发生)。基本上,我有一个C#应用程序随机在退出抛出未知异常。我已经成功地抓住它在调试器这一次,它原来是叫 Application.Exit()是扔 System.InvalidOperationException 以下消息:

I've got this really, really weird error that I've never been able to pin down (it happens very rarely). Basically, I have a C# application that was randomly throwing an unknown exception on exit. I've managed to catch it in the debugger this time, and it turns out that calling Application.Exit() is throwing a System.InvalidOperationException with the following message:

有一个第一次机会异常'System.InvalidOperationException'类型的mscorlib.dll中发生

A first chance exception of type 'System.InvalidOperationException' occurred in mscorlib.dll

补充资料:集合已修改;枚举操作可能无法执行。

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

我不知道的什么的这个系列已经涉嫌修改为,或者是谁是修改了它。

I'm not sure what this collection that has been allegedly modified is, or who it was that modified it.

堆栈跟踪是不是非常有帮助的:

The stack trace isn't very helpful:

mscorlib.dll中!System.Collections.ArrayList.ArrayListEnumeratorSimple.MoveNext()   + 0x13f字节System.Windows.Forms.dll的!System.Windows.Forms.Application.ExitInternal()   + 0x112字节System.Windows.Forms.dll的!System.Windows.Forms.Application.Exit(System.ComponentModel.CancelEventArgs   E)+ 0x65字节

mscorlib.dll!System.Collections.ArrayList.ArrayListEnumeratorSimple.MoveNext() + 0x13f bytes System.Windows.Forms.dll!System.Windows.Forms.Application.ExitInternal() + 0x112 bytes System.Windows.Forms.dll!System.Windows.Forms.Application.Exit(System.ComponentModel.CancelEventArgs e) + 0x65 bytes

任何想法如何,我可以找出其中的ArrayList它已被修改?我不认为这是什么,我明确地做,更可能的动作我做了手术的MS没想到中间过程中多数民众赞成修改.NET框架的基本状态。

Any idea how I can find out which ArrayList it is that has been modified? I don't think it's anything I'm doing explicitly, more likely an action I'm doing that's modifying the underlying state of the .NET framework during the middle of an operation that MS wasn't expecting..

推荐答案

不寻常的,以前从未见过这一点。该Application.ExitInternal()方法可以迭代Application.OpenForms集合。显然,这是收集得到修改,而它正在这样做。有几个可能的原因,我只能拿出之一。你的一个形式已经覆盖了OnFormClosing()方法或认购的FormClosing事件。而正在做一些修改OpenForms集合。可以配置表单对象或创建一个新的表单实例或修改窗体属性,导致窗口重新创建,像ShowInTaskbar。

Unusual, never seen this before. The Application.ExitInternal() method iterates the Application.OpenForms collection. Clearly this collection is getting modified while it is doing so. There are few possible causes for this, I can only come up with one. One of your forms has overridden the OnFormClosing() method or subscribed the FormClosing event. And is doing something that modifies the OpenForms collection. Could be disposing the form object or creating a new form instance or modifying a form property that causes the window to be re-created, like ShowInTaskbar.

您不会找到调用堆栈这个code回来。检查在[/的FormClosing code。评论code,如果你不能找到它快。

You won't find this code back in the call stack. Review your On/FormClosing code. Comment code out if you can't find it quickly.

这篇关于System.InvalidOperationException由于随叫随到收集修改Application.Exit()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆