簡體   English   中英

異常“無法訪問已處置的對象”來自非用戶代碼

[英]Exception “Cannot access a disposed object” is coming from non-user code

我通常理解異常Cannot access a disposed object 但是這一次它似乎起源於非用戶代碼。 我沒有發布代碼,因為這一次我不知道是哪一個:)關閉表單時偶爾會發生崩潰。 似乎正在進行一些自動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--

可能僅在調試器會話中引發此會話,到目前為止,我在生產中還沒有看到它。 (請參閱堆棧跟蹤的最底部項。)

  • 我的假設(僅由調試會話引起)是否正確? 還是我應該擔心生產中的相同問題?

  • 可以以某種方式避免這個問題嗎?

您提供的調用堆棧可能與已知的.Net問題有關。 請參閱MSDN-forum上以下線程
可能的解決方案是在FormClosing事件處理程序中對子窗體使用Me.Hide

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM