ASP.NET Article        
Skip Navigation Links

ASP.NET WaitPage Framework (4/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

3. Quick Guide To WaitPage Framework Usage

This section is intended as a quick summary of how to set up an app to use the WaitPage Framework, and is also for those who want to use the framework without necessarily wading through all the detailed explanation above.
  1. Derive a class from BaseTaskWaiter (This is referred to as TaskWaiter below) In this class:
    1. Write a function called StartTask to actually start your long running task. Have the parameters for the long running task passed in the class’s constructor.
    2. Override IsTaskFinished to query the long running task, and return true if the task has finished, and false otherwise.
    3. Override GetResults to return the results from the long running task. It’s good practice to throw an exception or return some kind of special value for the result, such as null, if the task hasn’t finished yet.

  2. Create a WaitPage Web Form. (WaitPage.aspx in the app’s root is the default URL expected by the framework. If you need a different one, see below in the ‘Other information’ section)
    1. Add at least a Label to the webform, to display the ‘waiting’ message.
    2. Make the WaitPage webform implement IWaitPage, which consists of the function SetWaitingMessage. Typical implementation is as follows:
          public void SetWaitingMessage(string waitMessage)
              lblWaitMessage.Text = waitMessage;
    3. In the WaitPage’s PageLoad call WaitPageHelper.DoWait(this). Be aware that this can return a WaitPageInvalidContextException.
    4. Make sure the user can’t use the browser’s back button by putting javascript into the WaitPage

  3. In another Web Form, add an event handler for the action which starts the long running task, typically a button handler. In this event handler, you need to:
    1. Construct an instance of the TaskWaiter class created above
    2. Register the object with the WaitPageHelper, by calling RegisterTaskWaiter. Also pass in the Result URL, which will be redirected to when the long running task completes.
    3. If the result page URL is the same page as that which has this event handler, then subscribe to the NotifyResultsStatus event in the TaskWaiter, after creation
    4. Start the task by calling the TaskWaiter’s StartTask function.
    5. If it starts OK, call WaitPageHelper.StartWaiting().

  4. If necessary, subscribe to the NotifyResultsStatus event in the TaskWaiter class, and write the handler. The handler should normally be static, and the bResultsReady argument should be stored in a session variable.

  5. In the Result page, if this is the same as the page starting the task: check the session variable used in Step 4 to see if results are ready, in Page_Load

  6. In all cases, in the Result page, get the results from the WaitPageHelper, cast to appropriate type and display or otherwise use.
< prev   1 | 2 | 3 | 4 | 5   next >
© 2006 Pete Beech