In this article I want to show three different ways to deal
with long running tasks in ASP.NET.
If such a task must be initiated from an ASP.NET web page, the thread that is
serving the page request is bound to the task until it completes or a timeout
occurs. ASP.NET and .NET Framework offer different ways to address this issue. In
the project used for this article, a sample page attempts to star a long running
task in three different ways.
1. Synchronously simply starting the task and waiting for
2. Asynchronously, using PageAsyncTask and other features
3. Asynchronously, using Asynchronous Delegates
Each of these options have pro and cons, and fit in
different scenarios, but also these options do not
require including the Async="true"
attribute in the page's @Page directive.
The first option entails to keep busy the thread that is
serving the request until the task completes. This could be a bottleneck,
especially if multiple users start multiple tasks. This condition will probably
end up to a 503 "Server Unavailable" error.
In this article I have used a sample web page that can start
the same long-running task in three different ways.
Figure 1 - Sample page used in tests