开发者

Async .aspx page

It seems async HTTP handler would scale better than sy开发者_StackOverflow社区nchronous HTTP handler. But then can a .aspx page be handled by a async handler? If so, how? or does some one need to implement the same using ajax only?


Async HttpHandlers can disconnect from the inbound IIS/ASP.NET process thread so effectively you are not tying up the ASP.NET request queue when creating an async handler (or using one of the Async ASP.NET Page mechanisms). This can be useful in very high volume sites that are processing large numbers of requests simultaneously.

Async handlers work well for IO bound operations (calling a Web Service, waiting for a SQL Server to run a long query) where your application just waits for a result to come back. However, it won't do much for you if your aysnc task is CPU intensive as the CPU load is not offloaded from the machine. They also don't work so well if your async task takes a long time to run because the request just appears hung. For more interactive UI when an operations takes a while AJAX and polling is the preferred approach - or some other callback mechanism that lets the user know that the task is done (email, or application based notifications).

For CPU intensive tasks to offload you have to build an Application Server type architecture where you offload processing to another machine and query for progress or have some other notification mechanism that lets you know of progress and returns the final result.

I have some slides and examples for both approaches here (async only for pages, offloaded via custom component provided in samples):

http://www.west-wind.com/Weblog/posts/543251.aspx (go towards the bottom of the post "Dealing with Long Running Requests in ASP.NET"


Async HTTP Handlers can help scalability when you have relatively long running I/O-bound tasks (fetch something from network, disk, database, Web service, ...) and you don't want to have your thread pool threads blocked while they are waiting for those tasks to finish. In other cases, they won't help. They don't magically make your application faster. You create async handlers by implementing the IHttpAsyncHandler interface.


The Page object (which processes .aspx pages) is an HttpHandler. You can configure it to use async by setting the Async property in the Page directive. Then follow one of the async code patterns in your code behind. For example:

protected void Page_Load(object sender, EventArgs e)
{
    PageAsyncTask pat =
        new PageAsyncTask(BeginAsync, EndAsync, null, null, true);
    this.RegisterAsyncTask(pat);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜