I have written following button click event handler in my code:
protected async void btnAsyncPostBack_Click(object sender, EventArgs e)
{
var sum = await GetSumAsync();
lblMessage.Text = string.Format("Sum = {0}", sum);
}
where GetSumAsync() can be assumed as any CPU intensive operation such as getting a lot of data from DB and applying heavy computations on it etc.
It returns a Task<T>.
My question is what is the difference between this event handler and a simple event handler. The code written above works fine, however, i was not able to find any noticable difference in its execution.
prabodhm
Participant
958 Points
232 Posts
Asynchronous event handler using async keyword
Sep 21, 2011 02:55 PM|LINK
I have written following button click event handler in my code:
protected async void btnAsyncPostBack_Click(object sender, EventArgs e) { var sum = await GetSumAsync(); lblMessage.Text = string.Format("Sum = {0}", sum); }where GetSumAsync() can be assumed as any CPU intensive operation such as getting a lot of data from DB and applying heavy computations on it etc.
It returns a Task<T>.
My question is what is the difference between this event handler and a simple event handler. The code written above works fine, however, i was not able to find any noticable difference in its execution.