diff --git a/src/modules/Elsa.Workflows.Core/Activities/Flowchart/Activities/Flowchart.cs b/src/modules/Elsa.Workflows.Core/Activities/Flowchart/Activities/Flowchart.cs index a8ae9d8b0..6706bcd93 100644 --- a/src/modules/Elsa.Workflows.Core/Activities/Flowchart/Activities/Flowchart.cs +++ b/src/modules/Elsa.Workflows.Core/Activities/Flowchart/Activities/Flowchart.cs @@ -128,10 +128,9 @@ public class Flowchart : Container if (!children.Any()) { var workflowExecutionContext = context.ReceiverActivityExecutionContext.WorkflowExecutionContext; - var scheduler = workflowExecutionContext.Scheduler; // If there is no pending work, complete the flowchart activity. - var hasPendingWork = scheduler.HasAny; + var hasPendingWork = HasPendingWork(workflowExecutionContext); if (!hasPendingWork) await flowchartActivityExecutionContext.CompleteActivityAsync(); @@ -141,6 +140,19 @@ public class Flowchart : Container context.StopPropagation(); } + /// + /// Checks if there is any pending work for the flowchart. + /// + private bool HasPendingWork(WorkflowExecutionContext workflowExecutionContext) + { + var scheduler = workflowExecutionContext.Scheduler; + var workItems = scheduler.List(); + var activityNodeIds = workItems.Select(x => x.ActivityId).ToList(); + var flowchartChildNodeIds = Activities.Select(workflowExecutionContext.FindNodeByActivity).Select(x => x.NodeId).ToList(); + var hasPendingWork = activityNodeIds.Intersect(flowchartChildNodeIds).Any(); + return hasPendingWork; + } + private bool HaveAllLeafsExecuted(FlowScope scope) { var leafs = Activities.Where(x => Connections.All(y => y.Source != x)).ToList();