AJAX-based Progress Indicators
With AJAX, Web applications may have a lifecycle similar to desktop applications. The user interacts with the user interface, a JavaScript event handler captures the DOM event and executes some code. At the end of the code, some data is generated to update the GUI. In this context, the code that expresses the required logic can either be local to the page (JavaScript) or remote (in a service). Is there a way to monitor the task? Is there a way to stop the task in case of need?
In Windows applications, a Cancel button to stop tasks in progress is nothing new. But in Web applications?
ASP.NET AJAX Extensions provides the UpdateProgress control to define a template that is displayed during a postback. This template can incorporate a Cancel button. There are a few limitations, though.
-
The UpdateProgress control works only with the partial rendering model. It doesn't work if you implement the task through a remote service.
-
The UpdateProgress control doesn't display dynamic information such as the time left.
-
You are offered an object model to cancel the ongoing task. But what you can really cancel is the socket through which the client receives results. No stop message is ever passed on to the remote task.
An emerging AJAX pattern can help--the Progress Indicator. The idea is that you design the remote task to access a data store periodically during its lifecycle. The task will write its current state to the store and will retrieve from there any messages the client sent. An additional client-side service will poll the data store and read the task's state. This information will then be rendered graphically in a dynamic panel or through a progress bar. Likewise, when the user cancels the task, a new message is placed in the store to stop the task.
Once the task receives the request to stop has to make a decision--aborting, rolling back, or perhaps compensating.
For more details and source code, check out my upcoming Cutting Edge columns on MSDN Magazine, July and August 2007.