orad
orad

Reputation: 16056

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?

Upvotes: 5

Views: 556

Answers (1)

sellotape
sellotape

Reputation: 8325

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

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

Upvotes: 4

Related Questions