开发者

Examples of when to use PageAsyncTask (Asynchronous asp.net pages)

From my understanding from reading about ASP.NET asynchronous pages, the method which executes when the asynchronous task begins ALWAYS EXECUTES between the prerender and the pre-render Complete events. So because the page's controls' events run between the page's load and prerender events, is it true that whatever the begin task handler (handler for BeginAsync below) produces, it can't be used in the controls' events? So for example, if the handler gets data from a database, the data can't be used in any of the controls' postback events?开发者_JAVA百科 Would you bind data to a data control after prerender?

PageAsyncTask pat = new PageAsyncTask(BeginAsync, EndAsync, null, null, true);
this.RegisterAsyncTask(pat);


Link by Tony_Henrich is very good, and here is another one of equal usefulness: http://msdn.microsoft.com/en-us/magazine/cc163725.aspx

All DataSource controls are automatically databound after Page_PreRender (if not already manually before that) - so yes you can bind data in all PageAsyncTask event handlers, or even in Page_PreRenderComplete (which starts only after every PageAsyncTask is finished or timeouts).

PageAsyncTask is best used when working with databases, web services, file I/O and all other operations on which CPU waits for the data to process it - but not for CPU intensive or long running calculations (when CPU is busy).

Having said all that, the page will process faster only if two or more PageAsyncTask are run in parallel - but, even with only one PageAsyncTask, the request thread is sent back to the pool (limited supply) while an I/O thread handles that operation, thus freeing IIS to receive more incoming requests until the task finishes (then it gets a request thread back from the pool, not necessarily that same one, and continues page processing).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜