在我的應用程序中,我看到有時我的主窗體上的Dispose方法顯然沒有理由被調用。我沒有通過UI關閉應用程序,我沒有發送關閉窗口消息或在任何地方調用Close(),但Dispose方法仍然被調用。以下是調用堆棧:爲什麼Dispose被調用?
Bitter.Shell.exe!Bitter.Shell.MainForm.Dispose(bool disposing = true) Line 853 C#
System.dll!System.ComponentModel.Component.Dispose() + 0x12 bytes
System.Windows.Forms.dll!System.Windows.Forms.ApplicationContext.Dispose(bool disposing) + 0x35 bytes
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.DisposeThreadWindows() + 0x33 bytes
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.Dispose(bool postQuit) + 0xf8 bytes
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason = -1, System.Windows.Forms.ApplicationContext context = {System.Windows.Forms.ApplicationContext}) + 0x276 bytes
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) + 0x61 bytes
System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.Form mainForm) + 0x31 bytes
Bitter.Shell.exe!Bitter.Shell.Program.Main() Line 105 + 0x26 bytes C#
如果內存不足以嘗試清理,CLR會調用它嗎?我知道Windows Mobile可以做到這一點,但並不認爲這發生在桌面世界。任何人都知道爲什麼這會被稱爲?
編輯:重新啓動後,我不再看到這個問題。所以它似乎是由於當時我的系統狀態。無論哪種方式,原因應該仍然是可以識別的。
Program.Main的內容並不重要 - 這是從Application.Run到來。 – SLaks 2009-09-11 16:08:06
是的,但我有圍繞Program.Main Application.Run try/catch。 – 2009-09-11 17:06:04
你發現了嗎? – Psddp 2017-01-14 00:06:11