Using the StateActivity Activity
The main component in a state machine workflow is the StateActivity activity. As events are captured at various points in a state machine workflow, different states are entered to handle the tasks associated with the events. During the workflow lifetime, the workflow may leave and enter several different states. These states connect to each other by using the SetStateActivity activity.
When you insert a new StateActivity activity into a workflow, you can add an EventDrivenActivity activity, a StateInitializationActivity activity, a StateFinalizationActivity activity, or additional StateActivity instances as children. Use the EventDrivenActivity activity when a StateActivity activity relies on an external event to occur before its child activities can execute.
When a child activity is executed more than once, a separate instance of the activity is created for each iteration. This enables the instances to execute independently (and potentially in parallel, as in the case of a ReplicatorActivity activity). As a consequence, the definition of the child activity in the activity tree (referred to as the template) is never executed and is always in the Initialized state. Access to the running instances of the template is provided by the composite activity that is the parent of the template. For example, in the case of the StateActivity activity, there is always one active instance, and GetDynamicActivity method retrieves this instance.
A StateInitializationActivity activity is a container for activities that execute upon entrance of the containing StateActivity activity. A StateFinalizationActivity activity is a container for child activities that execute when leaving the StateActivity activity.
For more information, see the StateActivity class in the System.Workflow.Activities namespace in the Windows Workflow Foundation Class Library reference.
For a code sample that demonstrates how to use the StateActivity activity, see Simple State Machine.