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.
精彩评论