EndActivity
Category: Common Steps
Namespace: CMS.Plugin.FlowManagement.Abstractions.FlowBusiness.Activitys
Base Class: BusinessActivity
Module: FlowManagement.Abstractions
Overview
EndActivity is the flow end node. When the flow runs to the end node, it terminates the entire flow instance and automatically ends other unprocessed steps in the flow instance. The end node supports automatic flow restart, enabling cyclic execution of the flow.
Business Scenarios
Applicable Scenarios
- Flow Termination: Marks normal flow termination
- Cyclic Flow: Automatically restarts after flow ends to achieve cyclic execution
- Performance Monitoring: Records total flow execution time
- Flow Cleanup: Automatically ends incomplete steps
Role in System
- Marks flow execution completion
- Calculates total flow time consumption
- Supports automatic flow restart
- Collects performance metrics
- Cleans up flow resources
Configuration Description
Basic Configuration
| Property Name | Type | Required | Default | Description |
|---|---|---|---|---|
| AutoResetEvent | bool | No | true | Whether to start a new flow instance after step execution (Repeat execution) |
| NeedTagChange | bool? | No | null | After flow restart, set condition to ensure business processing is triggered only when variables change |
| EnableCounter | bool | No | true | Whether to enable performance sampling |
Configuration Details
AutoResetEvent
Description: Controls whether to automatically restart after flow ends. When set to true, a new flow instance is automatically created after the flow ends.
Value Range: true or false
Notes:
- Suitable for flows requiring cyclic execution (e.g., monitoring, scheduled tasks)
- Effective on first execution
- Retains flow context data on restart
NeedTagChange
Description: Controls whether variable change is required to trigger flow restart. Avoids repeated processing of the same data.
Value Range: true, false, or null
Notes:
- true: Re-execute only when monitored variables change
- false/null: Execute every restart
- Can be dynamically controlled via flow context
NeedTagChange
EnableCounter
Description: Whether to enable performance counter to record flow execution time to the monitoring system.
Value Range: true or false
Notes:
- Used for performance monitoring and analysis
- Records total flow execution time
- Sends data to Metrics system
Flow Context
Input Parameters
| Parameter Name | Type | Description |
|---|---|---|
| NeedTagChange | bool | Dynamically control whether tag change is needed |
Output Parameters
No specific output parameters
Business Logic Description
Processing Flow
- Enter Node: Create work item and mark as completed
- End Flow: Call FinishFlowAsync to end flow instance
- Stop Timer: Stop flow timer
- Record Time: Record total flow execution time
- Restart Flow: If AutoResetEvent is enabled, create new flow instance
- Performance Sampling: If EnableCounter is enabled, record performance metrics
Special Behaviors
- Never Exit: EndActivity's CanExitAsync always returns false
- Auto Complete: Work item automatically marked as completed status
- Cleanup Incomplete Steps: Automatically ends other incomplete steps in the flow
Performance Monitoring
// Record total flow time consumption
Flow.Instance.Stopwatch?.Stop();
var elapsedMilliseconds = Flow.Instance.Stopwatch?.ElapsedMilliseconds;
// Send to monitoring system
Flow.Metrics.Counter(flowName, elapsedMilliseconds, "ms");
Usage Examples
Basic Example - Simple End
{
"Type": "EndActivity",
"Name": "Flow End",
"Alias": "End",
"AutoResetEvent": false,
"EnableCounter": true
}
Description: Does not restart after flow ends, records performance metrics.
Advanced Example - Cyclic Flow
{
"Type": "EndActivity",
"Name": "Loop End",
"Alias": "LoopEnd",
"AutoResetEvent": true,
"NeedTagChange": true,
"EnableCounter": true
}
Description: Automatically restarts after flow ends, but re-executes only when monitored variables change.
Complete Flow Example
{
"Name": "Monitoring Flow",
"Activities": [
{
"Type": "VariableMonitorActivity",
"Name": "Monitor Variable",
"Alias": "Monitor"
},
{
"Type": "ProcessDataActivity",
"Name": "Process Data",
"Alias": "Process"
},
{
"Type": "EndActivity",
"Name": "End and Restart",
"Alias": "End",
"AutoResetEvent": true,
"NeedTagChange": true
}
]
}
Notes
- ⚠️ Uniqueness: Each flow can have only one EndActivity
- ⚠️ Never Exit: EndActivity cannot have subsequent nodes
- ⚠️ Cyclic Flow: Avoid infinite loops when using AutoResetEvent
- ⚠️ Performance Impact: EnableCounter has slight performance overhead
- 💡 Best Practices:
- Recommend enabling NeedTagChange for cyclic flows to avoid repeated processing
- Recommend enabling EnableCounter in production for performance monitoring
- Ensure flow has clear termination conditions
Related Nodes
- BusinessActivity: Parent class
- ParallelEnd: Parallel flow end node
FAQ
Q1: Why can't there be nodes after EndActivity?
A: EndActivity's CanExitAsync always returns false, indicating the flow has ended and cannot continue execution.
Q2: How does AutoResetEvent work?
A: After the flow ends, the system calls ResetEventAsync to create a new flow instance, which starts execution from the beginning.
Q3: What is the use of NeedTagChange?
A: Prevents repeated processing of the same data. The restarted flow executes business logic only when monitored variables change.
Q4: How to view total flow execution time?
A: Check the "Exit, Total Time: XXXms" information in the logs, or view performance metrics in the monitoring system.
Update History
| Date | Version | Description |
|---|---|---|
| 2025-11-28 | 1.0 | Initial Release |
Last updated: 2025-11-28