Global.asax and handling exceptions that occur in spawned Threads
-
05-07-2019 - |
Question
I have an exception handler . In my asp.net application. It’s written in Global.asax. In the the Application_Error() method.
It works for Exceptions that happen in the context of pages and classes that are called as a result of a request to the application. But if I spawn a thread, as a result of a request (or other reason, like an application-based timer), and an Exception in that thread. It isn’t handled by the Global.asax. It causes Asp.net’s worker process to kill my application. Dead. If I plug into the AppDomain.CurrentDomain.UnhandledException handler, I see the exception that occurs in my Thread, but alas, this is too late. And the application still dies. Dead. Any advice?
Solution
exceptions in secondary threads are not reported by the unhandled-exception events
use SafeThread for your secondary threads
caveat: I am the author of the SafeThread article, and the app-monitoring product CALM