ASP.NET WaitPage Framework - Pete Beech

WaitPageFramework Namespace

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.

The WaitPage framework allows a 'wait page' to be integrated into such ASP.NET applications, which is then 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.

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.

A summary of the steps that need to be performed to integrate an ASP.NET Web Application with the WaitPage Framework, are:

  1. implement an interface called ITaskWaiter – the resulting class handles the call to the long-running process, determining when it is finished, gathering results from it, etc.
  2. create an actual WaitPage, containing some standard code (a call to a function in the wait page mechanism code),
  3. in the postback handler (e.g. a button handler) on the page which initiates the long running task (in our case WebForm1), create an object of the ITaskWaiter-implementing class, register this object with the wait page mechanism code, and then call a function to start the waiting.
  4. Create a ‘Results’ page to detect when results are ready, obtain them and then use and/or display them. This page could be the same page that has the postback element (such as a button) which initiated the start of the task

Namespace hierarchy

Classes

ClassDescription
BaseTaskWaiter BaseTaskWaiter is an abstract class which implements the ITaskWaiter and provides some of the implementation. It has a default waiting message, and also allows progress messages to be set. In the constructor, you must pass in the URL of the results page, and optionally a custom waiting message to override the default one if necessary, and a flag to indicate whether you want to use the progressMessage feature.
ResultsStatusNotificationArgs Event arguments class used to notify listeners about the status of the results.
WaitPageHelper The WaitPageHelper is the main coordinator class of the entire framework. It allows the registration of an ITaskWaiter object, checks this regularly to see whether the task has finished, and redirects to the results page when this happens.
WaitPageInvalidContextException Special WaitPage Framework exception class. Used to indicate that a WaitPage framework was called in an invalid context, normally when a function expects an ITaskWaiter to be registered when there isn't one.

Interfaces

InterfaceDescription
ITaskWaiter An object implementing ITaskWaiter is registered with the framework, and is used to wait for a particular long running task to finish, and to obtain the results when it does. The methods in ITaskWaiter allow the WaitPageHelper to determine if the task has finished, get results and send notification that results are ready, and to get an (optional) progress message. One method also provides the URL which the mechanism will redirect to as soon as the results of the long running task are available.
IWaitPage IWaitPage is a very simple interface with just one method, which has to be implemented by the Wait page(s) used in your application. It's sole purpose is to allow the Wait page mechanism to write out an optional progress message. This mechanism could easily be adapted to display a progress bar or something similar.

Delegates

DelegateDescription
NotifyResultsStatusEventHandler The delegate associated with the NotifyResultsStatus event in BaseTaskWaiter. See BaseTaskWaiter.