Issue is when i debug the application it execute in sequential order and jsonTask1 then LogEvent(...) and so on, why my LogEvent is not fire when doing async job of JsonTask1 and why control not goes to View if it is async processing of Json Tasks.
The xxxAsync method starts the operation and await allows to wait for this operation to be completed. This is the usual pattern when you have a single async operation or needs to make them one after the other.
The code sample shows how to call just the xxxAsync methods to start them all and then you'll await on all of them so that the next line happens when all are ended...
When you use await key word with a function then it start waiting for the result and not going further, to do some operations in parallel you need to initiate the functions and then wait for their completion after sync or other method that need to be executed
in parallel.
like
/// <returns></returns>
public async Task<IActionResult> Index()
{
//Fire
var t1 = GetAsync(); //starting
var t2 = GetAsync(); //starting
var t3 = GetAsync(); //starting
AnySyncMethod(); //processing
Debug.WriteLine("Other operation"); //done
Debug.WriteLine("Good going"); //done
//May be at this time t1 or t2 or t3 already done beause of parallel execution
var r1 = await t1; //waiting for result
var r2 = await t2; //waiting for result
var r3 = await t3; //waiting for result
return View();
}
Member
15 Points
23 Posts
Async and Await Blocking Ui
Oct 29, 2019 11:18 AM|Chan Leo|LINK
I am new to ASP.Net Mvc , i have gone through some async and await video and articles,so i use it in my action like
Issue is when i debug the application it execute in sequential order and jsonTask1 then LogEvent(...) and so on, why my LogEvent is not fire when doing async job of JsonTask1 and why control not goes to View if it is async processing of Json Tasks.
All-Star
48720 Points
18184 Posts
Re: Async and Await Blocking Ui
Oct 29, 2019 11:54 AM|PatriceSc|LINK
Hi,
This is mainly for web forms but https://docs.microsoft.com/en-us/aspnet/web-forms/overview/performance-and-caching/using-asynchronous-methods-in-aspnet-45#Parallel applies as well.
The xxxAsync method starts the operation and await allows to wait for this operation to be completed. This is the usual pattern when you have a single async operation or needs to make them one after the other.
The code sample shows how to call just the xxxAsync methods to start them all and then you'll await on all of them so that the next line happens when all are ended...
Contributor
2096 Points
1040 Posts
Re: Async and Await Blocking Ui
Oct 30, 2019 03:32 AM|Khuram.Shahzad|LINK
When you use await key word with a function then it start waiting for the result and not going further, to do some operations in parallel you need to initiate the functions and then wait for their completion after sync or other method that need to be executed in parallel.
like