How should I perform a long-running task in ASP.NET 4?

Preferentially, avoid having long tasks executing in such an environment.

Delegate long running tasks out to a stable system service via interoperability, leaving the web application responsive and only required for direct user requests.

Web applications have never been (and still aren’t) considered reliable systems – anyone who has ever used a browser has encountered (at least) a time-out, to be sure; and such inconvenience (for both parties) is not limited to this scenario. Of course, any system can crash, but the circumstances surrounding such an event on a system built-to-be-persistent ought to completely exceptional.

Windows services are designed to be long running, and if something goes wrong you’ve generally got more to worry about than your individual service.

Leave a Comment