views:

166

answers:

2

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

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

PageAsyncTask task2 =
new 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.

+4  A: 

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

Jacob
+1  A: 

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.

pmarflee