在我的应用程序中,我看到主窗体上的Dispose方法有时会被调用,显然没有任何原因。我不会通过UI关闭应用程序,也不会在任何地方发送关闭窗口消息或调用Close(),但是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做的正是这件事,但我没想到这会发生在桌面世界里。有人知道为什么会叫这个吗?
编辑:重新启动后,我不再看到此问题。因此,这似乎是由于我当时的系统状态造成的。无论哪种方式,原因都应该是可以识别的。
发布于 2009-09-11 16:04:31
UI线程中是否会抛出异常?
发布于 2009-09-11 16:06:18
在dispose方法中添加断点,并跟随调用堆栈查看代码中的哪些内容正在调用dispose方法。除非应用程序被系统或程序本身关闭,否则.NET在任何时候都不会调用dispose。
必须抛出异常。你在嵌套消息循环吗?
发布于 2009-09-11 16:06:20
您确定您的窗体没有以某种方式关闭吗?
调试编辑:单击Debug,Exceptions,make VS break on all managed exceptions,并查看是否有任何异常被接受。
https://stackoverflow.com/questions/1411805
复制相似问题