as we know, we can catch unhanle exception like this:
Catch UnHanle Exception in WinFormAppDomain.CurrentDomain.UnhandledException+=new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
Catch UnHanle Exception in WinForm    Application.ThreadException
+=new ThreadExceptionEventHandler(Application_ThreadException);

but if you call winForm like this, the style above will not affect all time, just occasionlly:

Catch UnHanle Exception in WinForm//add handler
Catch UnHanle Exception in WinForm

Catch UnHanle Exception in WinFormAppDomain.CurrentDomain.UnhandledException
+=new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
Catch UnHanle Exception in WinForm    Application.ThreadException
+=new ThreadExceptionEventHandler(Application_ThreadException);
Catch UnHanle Exception in WinForm
Catch UnHanle Exception in WinForm
//initial system
Catch UnHanle Exception in WinForm

Catch UnHanle Exception in WinFormApplication.Run(
new Form1());
Catch UnHanle Exception in WinForm
Catch UnHanle Exception in WinForm
//main form
Catch UnHanle Exception in WinForm

Catch UnHanle Exception in WinFormApplication.Run(
new Form2());
Catch UnHanle Exception in WinForm

 since when Application.Run, it begins one Message Loop in current main thread, and the thread exception's hook work.

but when Form1 close, the thread hook release, but then we begin the other message loop, the exception's hook release,

so if we hook it twice, what happen?

Catch UnHanle Exception in WinForm//add handler
Catch UnHanle Exception in WinForm

Catch UnHanle Exception in WinFormAppDomain.CurrentDomain.UnhandledException
+=new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
Catch UnHanle Exception in WinForm    Application.ThreadException
+=new ThreadExceptionEventHandler(Application_ThreadException);
Catch UnHanle Exception in WinForm
Catch UnHanle Exception in WinForm
//initial system
Catch UnHanle Exception in WinForm

Catch UnHanle Exception in WinFormApplication.Run(
new Form1());
Catch UnHanle Exception in WinForm
Catch UnHanle Exception in WinForm
//main form
Catch UnHanle Exception in WinForm
ThreadExceptionEventHandler(Application_ThreadException);
Catch UnHanle Exception in WinFormApplication.Run(
new Form2());

 

相关文章: