Search code examples
asp.netasynchronousasynchronous-pages

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 =
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.


Solution

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