From 8ddb88f9127257c990cdd6422b6b987515c9efe8 Mon Sep 17 00:00:00 2001 From: Whit Waldo Date: Wed, 9 Jul 2025 15:41:57 -0500 Subject: [PATCH 1/2] Supplemented to reflect an extension method introduced with 1.16 in the .NET SDK to simplify processing work in parallel but with an upper concurrency cap. Signed-off-by: Whit Waldo --- .../workflow/workflow-patterns.md | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/daprdocs/content/en/developing-applications/building-blocks/workflow/workflow-patterns.md b/daprdocs/content/en/developing-applications/building-blocks/workflow/workflow-patterns.md index 24db5b49252..55fdfa6ea54 100644 --- a/daprdocs/content/en/developing-applications/building-blocks/workflow/workflow-patterns.md +++ b/daprdocs/content/en/developing-applications/building-blocks/workflow/workflow-patterns.md @@ -624,6 +624,29 @@ await context.CallActivityAsync("PostResults", sum); {{< /tabs >}} +With the release of 1.16, it's even easier to process workflow activities in parallel while putting an upper cap on +concurrency by using the following extension methods on the `WorkflowContext`: + +{{< tabs ".NET" >}} + +{{% codetab %}} + +```csharp +//Revisiting the earlier example... +// Get a list of work items to process +var workBatch = await context.CallActivityAsync("GetWorkBatch", null); + +// Process deterministically in parallel with an upper cap of 5 activities at a time +var results = await context.ProcessInParallelAsync(workBatch, batch => context.CallActivityAsync("ProcessWorkItem", workItem), maxConcurrency: 5); + +var sum = results.Sum(t => t); +await context.CallActivityAsync("PostResults", sum); +``` + +{{% /codetab %}} + +{{< /tabs >}} + Limiting the degree of concurrency in this way can be useful for limiting contention against shared resources. For example, if the activities need to call into external resources that have their own concurrency limits, like a databases or external APIs, it can be useful to ensure that no more than a specified number of activities call that resource concurrently. ## Async HTTP APIs From 3259b08e4ee77ffba68af6d5b61e2f412944ef55 Mon Sep 17 00:00:00 2001 From: Whit Waldo Date: Thu, 10 Jul 2025 09:06:24 -0500 Subject: [PATCH 2/2] Fixed mismatched variable name Signed-off-by: Whit Waldo --- .../building-blocks/workflow/workflow-patterns.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daprdocs/content/en/developing-applications/building-blocks/workflow/workflow-patterns.md b/daprdocs/content/en/developing-applications/building-blocks/workflow/workflow-patterns.md index 55fdfa6ea54..af8f51b2869 100644 --- a/daprdocs/content/en/developing-applications/building-blocks/workflow/workflow-patterns.md +++ b/daprdocs/content/en/developing-applications/building-blocks/workflow/workflow-patterns.md @@ -637,7 +637,7 @@ concurrency by using the following extension methods on the `WorkflowContext`: var workBatch = await context.CallActivityAsync("GetWorkBatch", null); // Process deterministically in parallel with an upper cap of 5 activities at a time -var results = await context.ProcessInParallelAsync(workBatch, batch => context.CallActivityAsync("ProcessWorkItem", workItem), maxConcurrency: 5); +var results = await context.ProcessInParallelAsync(workBatch, workItem => context.CallActivityAsync("ProcessWorkItem", workItem), maxConcurrency: 5); var sum = results.Sum(t => t); await context.CallActivityAsync("PostResults", sum);