In Windows Form application, if the exception is eventually not processed, the AppDomain.CurrentDomain.UnhandledException will be triggered Event to make the final exception record (using this event does not prevent the end of the application). Before this event is triggered, the following conditions can determine whether the exception continues to propagate.
Main thread
Use the application.setunhandledexceptionmode (BOOL) method to pre-set the processing mode:
- If it is unhandledexceptionmode.throwexception, it continues to propagate.
- If unhandledexceptionmode.catchexception, the Application.ThreadException event is used for capture processing, and if an exception is thrown in this event, it will continue to propagate.
tasks, including those created with the new task () and TaskFactory
You can use the taskscheduler.unobservedtaskexception event for capture processing (note that this event will not fire until garbage collection is complete) to set the observed value:
- False indicates continued propagation
- If true, the propagation will not continue.
custom threads, including those created with ThreadPool using the new thread ()
No
Summarize unhandled exceptions in. NET Windows Form Application