- async await keywords are used for asynchronous operations
- awaiting a process puts in a separate task and returns the reference to that task.
- Once complete the runtime makes sure that the process starts execution back from where the await process occurs. This is called as continuation.
- we can use Task.WhenAll() method over a list of Tasks, which will ensure all the calls within the collection are completed before flagging as complete.
var tasks = new List<Task<int>>();
for (int i = 0; i < 10; i++)
{
tasks.Add(Task.Run<int>(() =>
{
Thread.Sleep(100);
return i;
}));
}
int[] task = await Task.WhenAll(tasks);
foreach (var i in task)
{
Console.WriteLine(i);
}