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>
the application behaves correct开发者_运维技巧ly and shows Windows Forms U-E default dialog, with Continue, Quit, call stack and all.
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.
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?
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? I want to let this job do 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. 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.
You cannot handle the latter, the program is dead and cannot continue. Displaying ThreadExceptionDialog is pointless.
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.
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.
Answer by Hans Passant seems sensible. 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.
精彩评论