Concurrent Tasks with WhenAll
Task.WhenAll completes when every supplied task has finished.
How it works
Run independent asynchronous operations concurrently.
Starting both tasks before awaiting them allows their delays to overlap.
Runnable C# example
Program.cs
using System;
using System.Threading.Tasks;
class Program
{
static async Task<int> Fetch(int value) { await Task.Delay(20); return value; }
static async Task Main()
{
int[] results = await Task.WhenAll(Fetch(20), Fetch(22));
Console.WriteLine(results[0] + results[1]);
}
}
42Practice with the debugger
Set a breakpoint on an important assignment or condition, click Debug, and inspect the local values before stepping to the next line.