diff --git a/src/modules/Elsa.Workflows.Runtime/Activities/DispatchWorkflow.cs b/src/modules/Elsa.Workflows.Runtime/Activities/DispatchWorkflow.cs index 2bdae954c..af45e30a2 100644 --- a/src/modules/Elsa.Workflows.Runtime/Activities/DispatchWorkflow.cs +++ b/src/modules/Elsa.Workflows.Runtime/Activities/DispatchWorkflow.cs @@ -49,18 +49,21 @@ public class DispatchWorkflow : Activity, IBookmarksPersistedHandler protected override async ValueTask ExecuteAsync(ActivityExecutionContext context) { var waitForCompletion = WaitForCompletion.TryGet(context); + var identityGenerator = context.GetRequiredService(); + var instanceId = identityGenerator.GenerateId(); + context.TransientProperties["ChildInstanceId"] = instanceId; // If we need to wait for the child workflow to complete, create a bookmark. if (waitForCompletion) { - var identityGenerator = context.GetRequiredService(); - var instanceId = identityGenerator.GenerateId(); - context.TransientProperties["ChildInstanceId"] = instanceId; context.CreateBookmark(new DispatchWorkflowBookmark(instanceId)); } else - // Otherwise, we can complete. + { + // Otherwise, we can complete. + await BookmarksPersistedAsync(context); await context.CompleteActivityAsync(); + } } ///