Task.WhenAll in .NET for Parallel Activities

The .NET SDK provides Workflow.WhenAnyAsync, but does not supply an equivalent to Task.WhenAll.

I would like to run several activities in parallel during a workflow and await the completion of them all.

I have considered either:
A) Task.WhenAll
B) Using Workflow.ExecuteActivityAsync to run several in parallel and then awaiting their completion individually in series with await

  1. Is it safe to use Task.WhenAll?
  2. What is the recommended / idiomatic way to run activities parallel?
1 Like

We cover this a bit in the README here. Basically half of the .NET task API is safe for custom scheduler and the other half is not. The only reason we have Workflow.WhenAnyAsync is due to an interesting .NET bug that will be fixed in newer versions anyways. So Task.WhenAny is not safe, but I have no reason (yet) to believe Task.WhenAll is unsafe, so you can use it.

I believe so based on my use. We have an event listener that will throw an exception if you accidentally get a task scheduled on the wrong scheduler.

Exactly that. Create a bunch of tasks and wait on them all.

1 Like