我通常理解异常无法访问已处置的对象
。但这一次它似乎源自非用户代码。我没有发布我的代码,因为这次我不知道是哪一个:)关闭表单时偶尔会发生崩溃。看起来一些自动 UI 刷新正在进行中:
Message: Cannot access a disposed object. Object name: 'Icon'. HResult: -2146232798 HelpLink: (null) Source: System.Drawing TargetSite: IntPtr get_Handle() StackTrace: at System.Drawing.Icon.get_Handle() at System.Drawing.Icon.get_Size() at System.Drawing.Icon.ToBitmap() at System.Windows.Forms.MdiControlStrip.GetTargetWindowIcon() at System.Windows.Forms.MdiControlStrip..ctor(IWin32Window target) at System.Windows.Forms.Form.UpdateMdiControlStrip(Boolean maximized) at System.Windows.Forms.Form.UpdateToolStrip() at System.Windows.Forms.Form.OnMdiChildActivate(EventArgs e) at System.Windows.Forms.Form.ActivateMdiChildInternal(Form form) at System.Windows.Forms.Form.WmMdiActivate(Message& m) at System.Windows.Forms.Form.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) --end of stack trace--
有可能这个仅在调试器 session 中抛出,到目前为止我还没有在生产中看到它。 (请参阅堆栈跟踪的最底部项目。)
我的假设(这仅是由调试 session 引起的)正确吗?或者我应该担心生产中的同样问题吗?
这个问题可以通过某种方式避免吗?
最佳答案
您提供的调用堆栈可能与已知的 .Net 问题相关。请参阅following thread at MSDN-forum .
可能的解决方案是在子表单的 FormClosing
事件处理程序中使用 Me.Hide
。
关于c# - 异常 "Cannot access a disposed object"来自非用户代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28699172/