本文介绍了Windows窗体未处理的异常对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的C#应用​​程序遇到U-E时获取默认Windows窗体未处理的异常"对话框.在vs 2005中,当我关闭app.conf中的jit调试时,如下所示:

I want to get Default Windows Forms Unhandled-Exception Dialog whenever my C# application encounters U-E.In vs 2005 when I turn off jit Debugging in app.conf like this:

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

该应用程序运行正常,并显示Windows窗体U-E默认对话框,其中包含继续",退出",调用堆栈"以及所有内容.

the application behaves correctly and shows Windows Forms U-E default dialog, with Continue, Quit, call stack and all.

但是,在vs 2008中,即使我禁用了jit,我仍然可以在同一台机器上或不同机器上使用调试",发送报告"和不发送"按钮获得默认的.NET Unhandled-Exception对话框.

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应用程序像在vs 2005中创建的应用程序一样显示Windows Forms U-E对话框?

How can I make my vs 2008 app act like the one I make in vs 2005, to show Windows Forms U-E dialog box?

请不要使用

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

仅仅因为我在vs 2005项目中不使用自定义处理程序,为什么在vs 2008中使用?我想让这份工作做CLR.

just because I don't use custom handler in my vs 2005 project, why would I use in vs 2008? I want to let this job do CLR.

感谢您的帮助

推荐答案

您正在谈论不同的异常处理功能.在退出并继续"中看到的 ThreadExceptionDialog 按钮由 Application.ThreadException事件.当响应Windows消息运行的事件处理程序引发异常时,只有在UI线程上发生异常时,它才会出现.但是,辅助线程中的任何异常都将通过AppDomain.UnhandledException轰炸程序.

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. 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. Any exception in a worker thread however will bomb the program through AppDomain.UnhandledException.

您无法处理后者,程序已死,无法继续.显示ThreadExceptionDialog是没有意义的.

You cannot handle the latter, the program is dead and cannot continue. Displaying ThreadExceptionDialog is pointless.

通过调用Application.SetUnhandledExceptionMode()禁用ThreadException事件,可以使程序炸弹一致.现在,每个未处理的异常都将触发AppDomain.UnhandledException并终止程序.那可能不是您想要的,但这是明智的选择.

You can make the program bomb consistently by disabling the ThreadException event by calling Application.SetUnhandledExceptionMode(). Now every unhandled exception will trigger AppDomain.UnhandledException and terminate the program. That's probably not what you want but is the wise choice.

还请注意,使用调试器运行程序时,将禁用ThreadException事件.这大概就是为什么您在VS2008中看到差异的原因.否则没有任何变化.

Also note that the ThreadException event is disabled when you run the program with a debugger. Which is presumably why you see a difference in VS2008. There have otherwise not been any changes.

这篇关于Windows窗体未处理的异常对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

查看更多