I'm trying to add a realtime progress report to my c#/asp.net 4.0 application for a slow loading page. I've look at the UpdatePanel and UpdateProgress Ajax controls but I don't think they're suitable.
Basically when the user click a button the page executes a number of tasks, I'd like the user to see an update as each one completes, instead of a report when they all complete and the page load completes.
The order thing would happen would be: 1. user click button to start 2. call method 1 3. when method 1 completes, user see "Method 1 done" 3. call method 2 etc.
Can anyone help with this?
This sort of asynchronous execution can be difficult to implement. A few solutions off the top of my head:
Totally asynchronous without AJAX:
Server generates a GUID for the task, and creates a record in your database. This might include:
Server spawns a thread to handle the task and passes in the Guid.
In the thread created in step (3):
Here's an example of easily creating a thread with a lambda.
Synchronous
Easier, but might cause some performance problems:
Effectively, the page keeps the connection open until the task is complete, and flushing the output periodically keeps the client from timing out. This may have problems with timeouts, etc, and your server configuration (output buffering, etc) might be an issue.
Background Task
Similar to the first asynchronous approach:
The difference between this and the first approach is that the thread lives in a separate process instead of IIS.
Each approach has its issues, of course, and there may be a simpler way to do this.