Reputation: 179
I'm using the Asynchronous page feature of ASP.NET 2.0 in my web application that is on ASP.NET 4.0.
I have set the begin and end task operations through AddOnPreRenderCompleteAsync
method, and
I have a label that says "operation started
" on page load and then the begin task starts.
Why am I not able to see this label until the asynchronous operation is completed? In effect, it's as good as a synchronous operation.
Shouldn't the page load and display the label while the asynchronous task is being carried out simultaneously?
Upvotes: 1
Views: 469
Reputation: 21365
Why am I not able to see this label until the asynchronous operation is completed?
Because you are creating an Async operation on the server side only. To fully understand the concept you need to understand the ASP.Net page life-cycle. In simple words, the response to the user won't return UNTIL THE PAGE HAS BEEN FULLY PROCESSED
So you might be wondering... What's the benefit then? Well the actual benefit is scalability. ASP.Net provides a fixed number of threads to be used to handle requests, when the max number of threads have been used, incoming requests will be placed in a queue blocking potentially the web application.
When you call an async method (like in your case), you are releasing the thread used by ASP.Net which then can be used to process incoming requests. When your long-time-consuming operation finishes, a light instance of the page is re-created in a new thread to process your end method
If you want to show the progress of an operation, you need to call the server-method using AJAX
Shouldn't the page load and display the label while the asynchronous task is being carried out simultaneously?
Nope
For more information:
How to display the Asynchronous results which one is first in asp.netweb application?
Upvotes: 1