I am learning about asynchronous operations in ASP .NET. I found an article here MSDN. The code works, but I want to be able to update the UI during the long process. It only shows the result after the process has finished. I am using the same code for the AsyncClass as in the link mentioned. Here is the code:
AsyncTask slowTask1 = new AsyncTask();
PageAsyncTask task = new PageAsyncTask(slowTask1.OnBegin, slowTask1.OnEnd, slowTask1.OnTimeout, "Async1", true);
Page.AsyncTimeout = new TimeSpan(0, 0, 5);
Page.RegisterAsyncTask(task);
// Page.ExecuteRegisteredAsyncTasks();
IAsyncResult result = slowTask1.OnBegin(this.Page,null,null,null);
WaitHandle waitHandle = result.AsyncWaitHandle;
waitHandle.WaitOne(2000, false);
if(result.IsCompleted)
{
slowTask1.OnEnd(result);
lbProgress.Text = slowTask1.GetAsyncTaskProgress();
Thread.Sleep(1000);
}
else
lbProgress.Text = slowTask1.GetAsyncTaskProgress();