States in a State Machine Workflow

When you generate the workflow, it consists of a single state and does not include an InitialState or a CompletedState. You must set these states during workflow development. Any activities to be executed in a particular state should be dropped into that state.

The InitialState of the state machine is the state in which the workflow will be placed, then you initialize a new instance of the workflow. This is a mandatory state; you must provide it for the workflow to be validated and compiled. State machine workflows can contain only one InitialState.

The CompletedState is the state that is designated as the termination point of the workflow; when the workflow transitions to the CompletedState, workflow execution is complete. No execution is possible in the CompletedState; the workflow runtime engine uses the state to release any resources, unload any values from memory, and terminate the workflow instance.

The CompletedState is not mandatory; you can have workflows that never complete, in which case they can be loaded and unloaded from memory as necessary and kept for long periods of time. This is especially useful for long-running processes, where you may need to store workflow instances for extended periods of time.

You drag StateActivity activities from the toolbox onto the workflow designer to build the structure of a state machine workflow. A StateActivity activity can contain StateInitializationActivity, EventHandlingActivity, SetStateActivity, and StateFinalizationActivity activities. You use these activities to define state transitions and behaviors so that you can define the execution flow of states in the workflow.

The workflow can contain any number of states, and should always include an InitialState.

For more information about adding activities to state machine workflows, see State Machine Workflows