ASP.NET exception handling in background thread

When I execute ThreadPool.QueueUserWorkItem, I do not want the unhandled exceptions to kill my whole process. So I am doing something like:

ThreadPool.QueueUserWorkItem(delegate() { try { FunctionIActuallyWantToCall(); } catch { HandleException(); } }); 

Is this the recommended template? There seems to be an easier way to do this. This is an asp.net-mvc application, if necessary.

+3
source share
1 answer

You need to catch the exception inside the callback (as in your example) to avoid propagation in the calling thread. This is the recommended model. If it is an ASP.NET application, you can also handle it in the Application_Error method in Global.asax

+2
source

All Articles