asynchronous ASP.NET


Thursday, October 11, 2007

If an ASP.NET webpage is involved in intense I/O operations (e.g., intense database, file, or web service calls) and the webpage is heavily used, performance problems can occur if worker process threads are waiting for I/O threads to become available (see my last article for more information).  In order to create scalable, efficient ASP.NET sites, asynchronous methods can be utilized to free up worker threads that would normally be frozen (and unusable) waiting for I/O threads to return.  The simplest way to employ asynchronous code in your ASPX page is to use the AddOnPreRenderCompleteAsync method in the Page_Load page method.  This method accepts two parameters, both delegates, which allow you to specify methods that will handle the beginning and end of the asynchronous operation you are trying to accomplish.  To make this asynchronous method work, you must also make sure to add the Async="true" page attribute to your web form’s Page directive.

This asynchronous code will fire between the PreRender and PreRenderComplete events of the page’s event lifecycle.  This means that the worker thread that was assigned to the HTTP request for this page will be put back in the thread pool right after the PreRender event has completed.  When the asynchronous code has finished, a worker thread will be pulled from the worker thread pool and the page will continue along its event lifecycle.

To see an example of this asynchronous model in action, you can go to MSDN (http://msdn2.microsoft.com/en-us/library/ba6dhx95(VS.80).aspx) or check out Jeff Prosise’s webcast from TechEd 2007 (http://msevents.microsoft.com/cui/WebCastEventDetails.aspx?EventID=1032345482&EventCategory=4&culture=en-US&CountryCode=US).


5:45:55 PM   | c# | asp.net | ado.net |


Comments



Post a comment on:

asynchronous ASP.NET

(HTML will not work within the comments)


Author  
Author Email  
Comment Title  
Comment  
 characters left
Captcha
Enter code in image: