I need to run multiple async tasks in a console application, and wait for them all to complete before further processing.
There\'s many articles out there, but I see
The best option I've seen is the following extension method:
public static Task ForEachAsync(this IEnumerable sequence, Func action) {
return Task.WhenAll(sequence.Select(action));
}
Call it like this:
await sequence.ForEachAsync(item => item.SomethingAsync(blah));
Or with an async lambda:
await sequence.ForEachAsync(async item => {
var more = await GetMoreAsync(item);
await more.FrobbleAsync();
});