ASP.NET Article        
Skip Navigation Links

ASP.NET WaitPage Framework (1/5)

[Note: Code is for ASP.NET 1.1, but converts to ASP.NET 2.0]

Download code and reference documentation for this article: (106KB)

View WaitPage Reference Documentation online

When a relatively long running process or task needs to be executed in an ASP.NET application, it isn’t ideal if the user merely sees a ‘hanging’ page in the browser. This article describes a framework for integrating a 'wait page' into such ASP.NET applications, which is displayed while the user waits for the completion of the long running task. This special ‘wait page’ can also display progress information, to reassure the user that the task is actually taking place.

[This article assumes a reasonable knowledge of ASP.NET 1.1 and the .NET framework. It’s also good to have some appreciation of the way in which ASP.NET page requests are handled, although this is not strictly necessary.]


When writing an ASP.NET application, sometimes it’s necessary to execute some task which will take a while to finish – for example, you might want to perform credit card validation via a webservice, validate some submitted files, or perhaps call a collection of webservices and process the responses, and so on. If the task is simply called synchronously by, say, a button handler, the browser page will appear to hang until the results of the task come back and the HTTP Response is created and returned to the user’s browser. It’s usually preferable to reassure the user that the application hasn’t crashed by presenting a ‘wait-page’ informing them that the task will take a while. It’s even better if the page can present some kind of progress information, or even a progress bar.

This article will explain a simple framework which can be used to implement custom Wait-Pages for an ASP.NET application – it will explain both how to use it, and also the full details of how it works. It can be fitted to whatever technique used to run the long running process asynchronously. (A future article will demonstrate a useful technique or pattern for running long running processes, and allowing results to be obtained at the appropriate time).

Long running tasks in ASP.NET applications

Before I start explaining the framework, I think it’s also useful to briefly look at the issues surrounding the execution of long running tasks from an ASP.NET application, because there are a couple of things you need to bear in mind when deciding how best to implement these.

The main thing to be aware of is that an ASP.NET worker thread which processes the request really shouldn't be tied up executing or waiting for a long running task to finish. Each request needs to be handled, and the thread returned to the pool, as quickly as possible. By doing this, the thread is available to process another request. This makes the application more responsive and scalable.

The implication of this is that you should never call a synchronous method which will perform a long running task directly from an ASP.NET application.

Another problem is, as mentioned above, the user will end up with the page just hanging, and the browser’s page-loading progress bar inching slowly forward as the long running process runs its course.

Now sometimes maybe it’s OK to have a hanging page, if the request will only take a few seconds, especially if you display a reassuring message which doesn't cause the user to think the whole thing has crashed. To do this correctly, and without blocking an ASP.NET worker thread, using asynchronous Http handlers would be the way to go (see appendix – Asynchronous Http Handlers). But if the process took a long time, a hanging page wouldn’t really be suitable without displaying some kind of progress information. Users like to be reassured that an application is still performing and has not crashed!

Technical Requirements and Restrictions

The mechanism currently relies on in-process session state - however it would not be too difficult to adapt to other kinds of session state.

It does not cater for the user branching out the browser session into separate browser windows, and starting tasks from both. (This would require some kind of key being used or generated when registering the task, and the subsequent passing around of the key, possibly via viewstate in the WaitPage or on the query string.)

Wait Page Framework

A ‘Wait page’ is simply a Webform which displays a message to the user, such as 'Please Wait', while some long running task is still running. It can also display additional information about the progress so far. The framework detects when the work has completed and automatically redirects to a 'results' page, which could also be, and often is, the page from which the long running task was initiated.

In the first section I'll demonstrate actually using the framework with a dummy long-running process and a little sample web-app, and in the 2nd section I'll explain in detail how everything works on the wait page framework mechanism side

1 | 2 | 3 | 4 | 5   next >
© 2006 Pete Beech