Cry about...
MS-Windows Troubleshooting


Thread Aborted exception


Symptom:

In a long running thread running in an ASP.NET application deployed to the server, the current activity is aborted with a Thread Aborted exception. Annoyingly when run locally in the development environment the Thread Aborted exception never seems to be raised.

The exception contains no information about what caused it to be raised, and it might be raised at different points in the code at different times.

Cause

This error/exception can indicate that the application pool is being recycled or stopped. This is also why it does not typically happen on a development PC because if the development server is being used and not IIS then application pools are never a factor.

If the exception is caused by the application pool being stopped or recycled then there will be a corresponding message in the System event log indicating why. For example:

A worker process with process id of '1234' serving application pool 'my-app' was shutdown due to inactivity. Application Pool timeout configuration was set to 5 minutes. A new worker process will be started when needed.

Possible remedy

Assuming that the pool is being shutdown due to inactivity then increase the "Idle Time-out (minutes)" value for the application pool serving the application.

This is the number of minutes that a worker process will remain idle before being shutdown. However "idle" is defined as responding to requests, not whether the thread is doing something. So this is not idle time but the length of time to wait after there have been no requests before shutting down the worker-process. Since the pool is managed by IIS and IIS does not know whether the thread is busy, it is perhaps reasonable for IIS to assume that the worker-process is idle if IIS has not seem any requests for the set length of time. On a busy site the server will not have to wait long between requests so the idle time-out setting does not come into play.

If you have a long running thread then increase this value. I have some sites where this is set to 60 minutes (i.e. an hour) and on one to 1440 minute (i.e. a day).


These notes have been tested on Windows 2008 Server, and may apply to other versions as well.



About the author: is a dedicated software developer and webmaster. For his day job he develops websites and desktop applications as well as providing IT services. He moonlights as a technical author and consultant.