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

AppDomain.CurrentDomain.UnhandledException+=new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
Application.ThreadException+=new ThreadExceptionEventHandler(Application_ThreadException);

//initial system

Application.Run(new Form1());

//main form

Application.Run(new Form2());
//add handler

AppDomain.CurrentDomain.UnhandledException+=new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
Application.ThreadException+=new ThreadExceptionEventHandler(Application_ThreadException);

//initial system

Application.Run(new Form1());

//main form
ThreadExceptionEventHandler(Application_ThreadException);
Application.Run(new Form2());


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













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?











