Reputation: 6441
I know that unhandled exceptions on background threads cause website shutting down so prevent website to shut down, I put below code code to Global.asax for prevent it.
protected void Application_Error(object sender, EventArgs e)
{
System.Web.HttpContext context = HttpContext.Current;
System.Exception ex = Context.Server.GetLastError();
context.Server.ClearError();
Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
}
But even this code doesn't prevent to website shut down. What I am missing in here ?
Upvotes: 0
Views: 621
Reputation: 6830
If you really need to manually spawn managed threads, I think the AppDomain.UnhandledException event is your only choice for non-fatal exceptions since Application_Error
does not get called for exceptions thrown outside the request processing context.
Depending on what you're doing in your background threads, you may want to switch to the async/await model for I/O-bound operations or TPL in general for CPU-bound tasks.
Upvotes: 1