acidzombie24 acidzombie24 - 1 year ago 80
ASP.NET (C#) Question

Why am i getting "Thread was being aborted" in

I am not sure why this happens and I never explicitly abort threads, so it's a bit of a surprise. But I log Exceptions and I am seeing:

System.Threading.ThreadAbortException - Thread was being aborted.

It appears to happen in a call to
. I am not sure how far this Exception goes. I don't think my threads ever terminate because I catch log and swallow the error.

Does anyone know why I'm getting these errors? Perhaps it's when I am forcefully terminating my server or asking it to reboot? If it isn't then what might be causing them?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download