异常 "Cannot access a disposed object" 来自非用户代码

Exception "Cannot access a disposed object" is coming from non-user code

我一般理解异常Cannot access a disposed object。但是这次它似乎起源于非用户代码。我没有发布我的代码,因为这次我不知道是哪一个 :) 关闭表单时偶尔会发生崩溃。似乎正在进行一些自动 UI 刷新:

消息:无法访问已处置的对象。
对象名称:'Icon'。
H结果:-2146232798
帮助链接:(空)
资料来源:System.Drawing
目标站点:IntPtr get_Handle()
堆栈跟踪:
       在 System.Drawing.Icon.get_Handle()
       在 System.Drawing.Icon.get_Size()
       在 System.Drawing.Icon.ToBitmap()
       在 System.Windows.Forms.MdiControlStrip.GetTargetWindowIcon()
       在 System.Windows.Forms.MdiControlStrip..ctor(IWin32Window 目标)
       在 System.Windows.Forms.Form.UpdateMdiControlStrip(布尔值最大化)
       在 System.Windows.Forms.Form.UpdateToolStrip()
       在 System.Windows.Forms.Form.OnMdiChildActivate(EventArgs e)
       在 System.Windows.Forms.Form.ActivateMdiChildInternal(表单表单)
       在 System.Windows.Forms.Form.WmMdiActivate(留言& m)
       在 System.Windows.Forms.Form.WndProc(消息& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(消息& m)
       在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(消息& m)
       在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       --堆栈跟踪结束--

这可能只是调试器会话引发的,到目前为止我还没有在生产中看到它。 (查看堆栈跟踪的最底部项目。)

您提供的调用堆栈可能与已知的 .Net 问题有关。见 following thread at MSDN-forum.
可能的解决方案是在子表单的 FormClosing 事件处理程序中使用 Me.Hide