Repository navigation
State Machine Evaluation of Transitions
When Event is sent to State Machine, Stateflows finds all Transitions triggered with this Event's type in current State's tree. Guards of these Transitions are then evaluated, one by one, and first Transition which Guard returns true is fired. That causes Source State to exit, Transition Effect is run, then Target State is entered.
An Internal Transition neither exits its source State nor enters a target State.
stateDiagram-v2
Source : exit / onExit
Source --> Target1 : Event1 [Guard1] / Effect1
Source --> Target2 : Event1 [Guard2] / Effect2
Target1 : entry / onEntry
Target2 : entry / onEntry
Let's consider above example:
- Current State of a State Machine is
Source, - Event
Event1is sent to a State Machine, -
Guard1is evaluated, returnsfalse, -
Guard2is evaluated, returnstrue, -
Source'sonExitis called, -
Effect2is called, -
Target2'sonEntryis called, - Execution is complete with
Target2as new current State of a State Machine.
When State contains multiple Transitions with various Guards, sometimes it is handy to use Else Transition - a Guard-less Transition which is fired when all other Transitions with the same Trigger fail to fire. Such Transition can be considered a fallback from all of these Transitions.
stateDiagram-v2
Source : exit / onExit
Source --> Target1 : Event1 [Guard1] / Effect1
Source --> Target2 : Event1 [Guard2] / Effect2
Source --> Target3 : Event1 [else] / Effect3
Target1 : entry / onEntry
Target2 : entry / onEntry
Target3 : entry / onEntry
Let's consider above example:
- Current State of a State Machine is
Source, - Event
Event1is sent to a State Machine, -
Guard1is evaluated, returnsfalse, -
Guard2is evaluated, returnsfalse, -
Source'sonExitis called, -
Effect3is called, -
Target3'sonEntryis called, - Execution is complete with
Target3as new current State of a State Machine.
Else-ness of Transition is based on a Trigger type, not Transition type!
Transitions on deeper active states are evaluated before transitions on their active ancestors.
stateDiagram-v2
state State1 {
Substate1 : exit / onExit
Substate2 : entry / onEntry
Substate1 --> Substate2 : Event1 / Effect1
}
State1 --> State2 : Event1
Let's consider above example:
- Current States of a State Machine are
State1/Substate1, - Event
Event1is sent to a State Machine, - Both available Transitions are Triggered by
Event1, but inner Transition has precedence over outer Transition, -
Substate1'sonExitis called, -
Effect1is called, -
Substate2'sonEntryis called, - Execution is complete with
State1/Substate2as new current States of a State Machine.
For the purposes of fine-tuning specific Transition like "from parent state to substate (direct or not)" or "from substate (direct or not) to state" UML specifies that Transitions might be local or external. The difference is this:
- when local Transitions happens:
- Transition Source will not be exited and reentered if Transition Target is a substate (direct or not) of a Source,
- Transition Target will not be exited and reentered if Transition Source is a substate (direct or not) of a Target,
- when external (non-local) Transition happens, Transition Source is always exited and Transition Target is always entered.
Stateflows provides a way to change Transition localness by calling SetIsLocal() method on the level of Transition definition:
Definition fragment (inside the builder callback):
/* fragment of State Machine definition */
.AddCompositeState("SomeState", b => b
.AddTransition<TriggerEvent>("Substate", b => b
.SetIsLocal(false)
)
.AddState("Substate")
)By default, all Transitions in Stateflows State Machines are local.
Home page Support Code licensed under an MIT-style License. Documentation licensed under CC BY 4.0. © by Mikołaj Milewski, 2026
Overview
Installation
Runtimes
Orleans runtime
Concepts
Events and Structural Events
Messaging Patterns
Validation
Scheduling
Observability
Behaviors
Behavior Values
Dependency Injection
Behavioral Groups
State Machines
Concepts
State Identity
In-State Event Deferrals
Evaluation of Transitions
Exception Handling
Building blocks
Regions
States
State
Composite State
Orthogonal State
Final State
Pseudostates
Choice
Junction
Fork
Join
History
Transitions
Transition
Default Transition
Internal Transition
Activities
Concepts
Exception Handling
Implicit Fork and Join
Tokens
Building blocks
Nodes
Action Node
Decision Node
Merge Node
Initial Node
Final Node
Input Node
Output Node
Fork Node
Join Node
Accept Event Action Node
Send Event Action Node
Publish Event Action Node
Time Event Action Node
Data Store Node
Structured Activity Node
Iterative Activity Node
Parallel Activity Node
Flows
Data Flow
Control Flow
Actions
Entities
Fields
Mutations
Projections
Extensions
ClearScript
FluentValidation
JSON definitions
Minimal APIs
OneOf
OpenTelemetry
PlantUML
Scheduling