开发者

In ASP.NET asynchronous pages, is it possible to execute 2 sequential, asynchronous tasks?

In ASP.NET, you can run asynchronous tasks as follows:

PageAsyncTask task1 = 
new PageAsyncTask(BeginAsyncOperation1, EndAsyncOperation1, TimeoutAsyncOperation1, state);
RegisterAsyncTask(task1);

PageAsyncTask task2 =
ne开发者_如何学运维w PageAsyncTask(BeginAsyncOperation2, EndAsyncOperation2, TimeoutAsyncOperation2, state);
RegisterAsyncTask(task2);

However, suppose you need to ensure that task1 completes before task2 executes. Is this possible?

My understanding is that these tasks would run in parallel.


The easiest solution would be to launch task2 within the "EndAsyncOperation1" handler.


If task1 needs to complete before task2, you could consider creating a third operation that encapsulates synchronous calls to BeginAsyncOperation1 and BeginAsyncOperation2 and run that operation asynchronously. The work for the second task will not begin until the first task has completed.


The solution is in the PageAsyncTask constructor. Set the boolean flag for "parallel" to be false and they will run sequentially.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜