Why am I getting "Thread was being aborted" in ASP.NET?
Solution 1:
Nope, ThreadAbortException
is thrown by a simple Response.Redirect
Solution 2:
ASP.NET spawns and kills worker processes all the time as needed. Your thread may just be getting shut down by ASP.NET.
Old Answer:
Known issue: PRB: ThreadAbortException Occurs If You Use Response.End, Response.Redirect, or Server.Transfer
Response.Redirect ("bla.aspx", false);
or
try
{
Response.Redirect("bla.aspx");
}
catch (ThreadAbortException ex)
{
}
Solution 3:
If you spawn threads in Application_Start
, they will still be executing in the application pool's AppDomain
.
If an application is idle for some time (meaning that no requests are coming in), or certain other conditions are met, ASP.NET
will recycle the entire AppDomain
.
When that happens, any threads that you started from that AppDomain
, including those from Application_Start
, will be aborted.
Lots more on application pools and recycling in this question: What exactly is Appdomain recycling
If you are trying to run a long-running process within IIS/ASP.NET
, the short answer is usually "Don't". That's what Windows Services are for.
Solution 4:
For a web service hosted in ASP.NET, the configuration property is executionTimeout:
<configuration> <system.web>
<httpRuntime executionTimeout="360" />
</system.web>
</configuration>
Set this and the thread abort exception will go away :)