简体   繁体   English

Windows窗体未处理 - 异常对话框

[英]Windows Forms Unhandled-Exception Dialog

I want to get Default Windows Forms Unhandled-Exception Dialog whenever my C# application encounters UE. 我想在我的C#应用​​程序遇到UE时获得Default Windows Forms Unhandled-Exception Dialog。 In vs 2005 when I turn off jit Debugging in app.conf like this: 在vs 2005中我在app.conf中关闭jit Debugging,如下所示:

<configuration>
   <system.windows.forms jitDebugging="false" />
<configuration>

the application behaves correctly and shows Windows Forms UE default dialog, with Continue, Quit, call stack and all. 应用程序行为正常并显示Windows窗体UE默认对话框,包括继续,退出,调用堆栈和所有。

However in vs 2008, on the same machine or different, even though I diable jit I still get Default .NET Unhandled-Exception Dialog, with Debug, Send Report and Don't Send buttons. 然而在vs 2008中,在同一台机器上或不同的机器上,即使我使用jit jit,我仍然可以通过Debug,Send Report和Do not Send按钮获得Default .NET Unhandled-Exception Dialog。

How can I make my vs 2008 app act like the one I make in vs 2005, to show Windows Forms UE dialog box? 如何使我的vs 2008应用程序像我在vs 2005中制作的那样,显示Windows Forms UE对话框?

Please do not recommend to use 请不要使用

AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

just because I don't use custom handler in my vs 2005 project, why would I use in vs 2008? 仅仅因为我在我的vs 2005项目中没有使用自定义处理程序,为什么我会在vs 2008中使用? I want to let this job do CLR. 我想让这份工作做CLR。

Any help is appreciated 任何帮助表示赞赏

You are talking about different exception handling features. 您正在谈论不同的异常处理功能。 The ThreadExceptionDialog you see with the Quit and Continue buttons is triggered by the Application.ThreadException event . 使用“退出并继续”按钮看到的ThreadExceptionDialogApplication.ThreadException事件触发。 It will only ever appear if the exception happens on the UI thread, when an event handler that runs in response to a Windows message throws an exception. 只有在UI线程上发生异常时才会出现,当响应Windows消息而运行的事件处理程序抛出异常时。 Any exception in a worker thread however will bomb the program through AppDomain.UnhandledException. 但是,工作线程中的任何异常都会通过AppDomain.UnhandledException轰炸程序。

You cannot handle the latter, the program is dead and cannot continue. 你不能处理后者,程序已经死了,无法继续。 Displaying ThreadExceptionDialog is pointless. 显示ThreadExceptionDialog是没有意义的。

You can make the program bomb consistently by disabling the ThreadException event by calling Application.SetUnhandledExceptionMode(). 您可以通过调用Application.SetUnhandledExceptionMode()来禁用ThreadException事件,从而一致地制作程序炸弹。 Now every unhandled exception will trigger AppDomain.UnhandledException and terminate the program. 现在每个未处理的异常都会触发AppDomain.UnhandledException并终止程序。 That's probably not what you want but is the wise choice. 这可能不是你想要的,但却是明智的选择。

Also note that the ThreadException event is disabled when you run the program with a debugger. 另请注意,使用调试器运行程序时,将禁用ThreadException事件。 Which is presumably why you see a difference in VS2008. 这可能就是为什么你看到VS2008的不同之处。 There have otherwise not been any changes. 否则没有任何变化。

Answer by Hans Passant seems sensible. Hans Passant的回答似乎很明智。 However, even though you say you don't want to I still recommend a handler on AppDomain.CurrentDomain.UnhandledException to make sure you determine what happens when your application crashes unexpectedly. 但是,即使您说您不想,我仍然建议AppDomain.CurrentDomain.UnhandledException使用处理程序,以确保您确定应用程序意外崩溃时会发生什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Windows Forms应用程序中未处理的异常 - Unhandled exception in Windows Forms app Windows Forms 未处理的异常崩溃 - Windows Forms Unhandled Exception Crash 抑制未处理的异常对话框? - Suppress unhandled exception dialog? Windows服务中未处理的异常 - Unhandled Exception in Windows Service 保存文件对话框未处理的异常 - Save file dialog An unhandled exception 防止出现未处理的异常对话框 - Preventing Unhandled Exception Dialog Appearing System.Windows.Forms.dll中发生类型为&#39;System.ArgumentException&#39;的未处理异常 - an unhandled exception of type 'System.ArgumentException' occurred in System.Windows.Forms.dll System.Windows.Forms.d中发生了类型为&#39;System.ObjectDisposedException&#39;的未处理异常 - An unhandled exception of type 'System.ObjectDisposedException' occurred in System.Windows.Forms.d System.Windows.Forms.dll中发生了类型为&#39;System.StackOverflowException&#39;的未处理异常 - An unhandled exception of type 'System.StackOverflowException' occurred in System.Windows.Forms.dll “System.Windows.Forms.dll中发生了&#39;System.StackOverflowException&#39;类型的未处理异常” - “An unhandled exception of type 'System.StackOverflowException' occurred in System.Windows.Forms.dll”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM