AppDomain.CurrentDomain.UnhandledException
+=
new
UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
but if you call winForm like this, the style above will not affect all time, just occasionlly:
//
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());
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());
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?
//
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());
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());