Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can this parallel async call be simplified?

I think async/await keywords here are redundant.

Parallel.Invoke(
    async () => await DoSomethingAsync(1).ConfigureAwait(false),
    async () => await DoSomethingAsync(2).ConfigureAwait(false)
);

Given a number of task-returning methods, is there any more straightforward way to run them in parallel and return when all are complete?

like image 399
orad Avatar asked Dec 02 '16 02:12

orad


1 Answers

await Task.WhenAll(DoSomethingAsync(1), DoSomethingAsync(2));

Optionally add .ConfigureAwait(false) to the WhenAll(), depending on context.

like image 62
sellotape Avatar answered Oct 31 '22 23:10

sellotape