How do you run multiple async operations concurrently?
Short answer
Start the tasks without awaiting each immediately, then await Task.WhenAll to run them in parallel and wait for all.
Advertisement
AModel answer
Start the tasks without awaiting each immediately, then await Task.WhenAll to run them in parallel and wait for all.
var t1 = h.GetStringAsync(a);
var t2 = h.GetStringAsync(b);
var r = await Task.WhenAll(t1, t2);Real-world example
Fetching price, stock and reviews at once to cut page latency.