If you think you’re going to do progress monitoring in ASP.NET just like you would do it in a Windows Forms application, think again — it’s not possible.
Why is it so difficult?
The cause of the problem has to do with the basics of how browsers and the HTTP protocol work. The problem is the same for any long-running server-side task. Let’s analyze it…
Everybody knows HTTP works like this: A browser sends an HTTP request (POST or GET) to a web server and waits for the HTTP response containing HTML. The browser renders the HTML as it’s arriving. Your server-side ASP.NET code handling the HTTP request includes a long-running task, and that is what you hope to progress monitor. But there is a problem:
1) The HTTP response is not complete until the long-running server-side task is completed.
2) The browser cannot update a progress element on the page until the full HTTP response has been received and the page is fully rendered.
So here’s the problem: you cannot begin to monitor the progress of the server-side task until the server-side task has completed.
What about AJAX? Ajax is nice, but it doesn’t solve the problem. To use AJAX to properly monitor the progress of a server-side task, you need additional infrastructure on the server-side. The long-running task would need to run in a separate process such that the ASP.NET page can complete while the server-side task remains running. Then… subsequent AJAX HTTP requests would need to provide information so the ASP.NET code handling the AJAX request can properly find it’s task, query on the progress, and send an HTTP response.