StateMachineWorkflowActivity Class



This API is now obsolete.

Serves as the root container for state machine workflows. Contains event-driven activities and states.

public ref class StateMachineWorkflowActivity : System::Workflow::Activities::StateActivity
[System.Drawing.ToolboxBitmap(typeof(System.Workflow.Activities.StateMachineWorkflowActivity), "Resources.StateMachineWorkflowActivity.png")]
[System.Obsolete("The System.Workflow.* types are deprecated.  Instead, please use the new types from System.Activities.*")]
public class StateMachineWorkflowActivity : System.Workflow.Activities.StateActivity
type StateMachineWorkflowActivity = class
    inherit StateActivity
Public Class StateMachineWorkflowActivity
Inherits StateActivity


The following code example shows how to create a new instance of the StateMachineWorkflowActivity class and use it to implement a basic state machine to transition between three states. This code example is part of the SimpleStateMachineWorkflow SDK sample from the StateMachineWorkflow.cs file. For more information, see Simple State Machine.

this.WhileLoop = new System.Workflow.Activities.WhileActivity();
this.Parallel = new System.Workflow.Activities.ParallelActivity();
this.Sequence1 = new System.Workflow.Activities.SequenceActivity();
this.Sequence2 = new System.Workflow.Activities.SequenceActivity();
this.ConsoleMessage1 = new System.Workflow.Activities.CodeActivity();
this.ConsoleMessage2 = new System.Workflow.Activities.CodeActivity();
// WhileLoop
codecondition1.Condition += new System.EventHandler<System.Workflow.Activities.ConditionalEventArgs>(this.WhileCondition);
this.WhileLoop.Condition = codecondition1;
this.WhileLoop.Name = "WhileLoop";
// Parallel
this.Parallel.Name = "Parallel";
Me.WhileLoop = New System.Workflow.Activities.WhileActivity()
Me.Parallel = New System.Workflow.Activities.ParallelActivity()
Me.Sequence1 = New System.Workflow.Activities.SequenceActivity()
Me.Sequence2 = New System.Workflow.Activities.SequenceActivity()
Me.ConsoleMessage1 = New System.Workflow.Activities.CodeActivity()
Me.ConsoleMessage2 = New System.Workflow.Activities.CodeActivity()
' WhileLoop
AddHandler codecondition1.Condition, AddressOf Me.WhileCondition
Me.WhileLoop.Condition = codecondition1
Me.WhileLoop.Name = "WhileLoop"
' Parallel
Me.Parallel.Name = "Parallel"



This material discusses types and namespaces that are obsolete. For more information, see Deprecated Types in Windows Workflow Foundation 4.5.

The StateMachineWorkflowActivity is an activity container used to create workflows that follow a state machine model.

The StateMachineWorkflowActivity is a CompositeActivity, which means the StateMachineWorkflowActivity can contain other activities. The StateMachineWorkflowActivity and the EventDrivenActivity activities are the only permitted child activities of the StateMachineWorkflowActivity. EventDrivenActivity activities are permitted because the root activity itself behaves like a state. Therefore, you can have EventDrivenActivity activities at the root level that are used by all the State activities in the StateMachineWorkflowActivity. EventDrivenActivity activities at this level provide a global mechanism for processing workflow events and automate state transitions. StateActivity activities provide a mechanism to define the various stages in the model.

The StateMachineWorkflowActivity has properties that are required for the execution of the state machine workflow. Most notably, the StateMachineWorkflowActivity has two properties that are important: InitialStateNameProperty and CompletedStateNameProperty.

The InitialStateNameProperty of the state machine is the state in which the state machine is when an instance of the state machine is created. The InitialStateNameProperty property is mandatory and must be provided when a StateMachineWorkflowActivity is created. The InitialStateNameProperty of the state machine is like any other state activity that is contained within the state machine. The state activity can be a direct child of the StateMachineWorkflowActivity root activity and a StateMachineWorkflowActivity can have only one InitialStateNameProperty.

The CompletedStateNameProperty of the StateMachineWorkflowActivity is a StateActivity activity that is designated as the end state of the StateMachineWorkflowActivity. When a transition is made to the CompletedStateNameProperty, the workflow execution is completed. The CompletedStateNameProperty is not mandatory. This means that you can have a StateMachineWorkflowActivity that is not completed. This does not mean that the state machine workflow is always active in memory. The StateMachineWorkflowActivity might be unloaded as it waits for an event.

StateMachineWorkflowActivity activities that never complete are especially useful in processing long running business transactions, as in the case of a purchase order received by a supplier. The fact that the purchase order was fulfilled does not mean that the purchase order process is over. The goods that are part of the purchase order might be returned or the purchase order might be amended and have additional items added to it after the fulfillment. Sometimes there might be a requirement to keep the purchase order records for an extended period of time for legal or other purposes. The fact that a workflow does not finish just means that the workflow remains in an unloaded state. There may be a case for retiring the workflows, which means that after a set period of time the workflow instance may be forced to shut down.



Initializes a new instance of the StateMachineWorkflowActivity class.


Initializes a new instance of the StateMachineWorkflowActivity class using the name of the activity.



Represents the DependencyObject that targets the CompletedStateName property.


Represents the DependencyObject that targets the InitialStateName property.


The name of the WorkflowQueue that is used to change the state of a StateMachineWorkflowActivity. This field is constant.


Holds the string value of the change tracking data key; "StateActivity.StateChange". This field is a constant.

(Inherited from StateActivity)



Gets the object representing the collection, ActivityCollection, of all child activities.

(Inherited from CompositeActivity)

Gets or sets a value which controls whether the individual activities within Activities can be modified.

(Inherited from CompositeActivity)

Gets or sets the end StateActivity of the workflow.


Gets the name of the currently executing StateActivity.


Gets or sets the user-defined description of the Activity.

(Inherited from Activity)

Gets the value that indicates whether this instance is in design or run-time mode.

(Inherited from DependencyObject)

Gets or sets an ActivityCondition that determines whether dynamic updates can be made in the workflow, when overridden in a derived class.


Gets or sets a value that indicates whether this instance is enabled for execution and validation.

(Inherited from Activity)

Gets the read-only collection that represents the subset of Activities that are enabled.

(Inherited from CompositeActivity)

Gets the ActivityExecutionResult of the last attempt to run this instance.

(Inherited from Activity)

Gets the current ActivityExecutionStatus of this instance.

(Inherited from Activity)

Gets or sets the StateActivity in which the StateMachineWorkflowActivity is when an instance of the state machine is created.


Gets information about whether the activity is executing within the default ActivityExecutionContext of the workflow instance.

(Inherited from Activity)

Gets or sets the name of this instance. This name must conform to the variable naming convention of the programming language that is being used in the Workflow project.

(Inherited from Activity)

Gets the CompositeActivity that contains this Activity.

(Inherited from Activity)

Gets the parent DependencyObject in the DependencyObject graph.

(Inherited from DependencyObject)

Gets the name of the previously executed StateActivity.


Gets the qualified name of the activity. Qualified activity names are always unique in a workflow instance.

(Inherited from Activity)

Gets or sets a reference to the Site component of the DependencyObject.

(Inherited from DependencyObject)

Gets an IDictionary that associates custom data with this class instance.

(Inherited from DependencyObject)

Gets the Guid associated with the instance.

(Inherited from Activity)


AddHandler(DependencyProperty, Object)

Adds a handler for an event of a DependencyObject.

(Inherited from DependencyObject)

Applies the WorkflowChanges manifest in the parameter to this instance.

(Inherited from CompositeActivity)

Cancels the execution of the StateActivity.

(Inherited from StateActivity)

Creates a deep copy of the Activity.

(Inherited from Activity)

Releases all the resources used by the DependencyObject.

(Inherited from DependencyObject)

Calls Dispose(Boolean) on this instance, and optionally calls Dispose() on all child activities of this instance.

(Inherited from CompositeActivity)

Determines whether the specified object is equal to the current object.

(Inherited from Object)

Executes the StateActivity.

(Inherited from StateActivity)

Returns the instance of the Activity whose name is requested from the set of all activities running under the root activity of this instance, which is within the workflow.

(Inherited from Activity)
GetActivityByName(String, Boolean)

Returns the instance of the Activity whose name is requested from the set of all activities under the root the Activity of this instance if the second parameter is false and under the current Activity if the second parameter is true.

(Inherited from Activity)

Provides access to the ActivityBind associated with the specific DependencyProperty.

(Inherited from DependencyObject)
GetBoundValue(ActivityBind, Type)

Retrieves the Object that is the subject of an ActivityBind.

(Inherited from DependencyObject)

Returns an array that contains all of the currently executing instances of the specified activity.

(Inherited from CompositeActivity)

Gets the executing instance of the Activity that corresponds to the specified child activity name.

(Inherited from StateActivity)

Serves as the default hash function.

(Inherited from Object)

Gets an array that contains the delegates for the specified DependencyProperty.

(Inherited from DependencyObject)

Gets the Type of the current instance.

(Inherited from Object)

Provides access to the value of the designated DependencyProperty.

(Inherited from DependencyObject)

Provides access to the bound object of a DependencyProperty and bypasses the GetValue(DependencyProperty) override.

(Inherited from DependencyObject)
HandleFault(ActivityExecutionContext, Exception)

Called when an exception is raised within the context of the execution of this instance.

(Inherited from CompositeActivity)

Initializes the StateActivity using the service provider.

(Inherited from StateActivity)

Performs initialization on dependency properties when overridden in a derived class.

(Inherited from DependencyObject)
Invoke<T>(EventHandler<T>, T)

Subscribes an EventHandler and invokes that delegate.

(Inherited from Activity)
Invoke<T>(IActivityEventListener<T>, T)

Subscribes an IActivityEventListener<T> and invokes that delegate.

(Inherited from Activity)

Indicates whether the value of a DependencyProperty is set as a binding. See SetBinding(DependencyProperty, ActivityBind).

(Inherited from DependencyObject)

Creates a shallow copy of the current Object.

(Inherited from Object)

Determines whether the metaproperties of this DependencyObject equals the metaproperties of the parameterized DependencyObject.

(Inherited from DependencyObject)
OnActivityChangeAdd(ActivityExecutionContext, Activity)

Determines if the activity being added is an EventDrivenActivity and if so, verifies whether the newly added event driven needs to be subscribed.

(Inherited from StateActivity)
OnActivityChangeRemove(ActivityExecutionContext, Activity)

Called when an activity is removed.

(Inherited from CompositeActivity)

Called by the workflow runtime engine every time the ActivityExecutionContext for this activity is loaded.

(Inherited from CompositeActivity)

Called by the workflow runtime engine every time the ActivityExecutionContext for this activity is unloaded.

(Inherited from CompositeActivity)

Called by the workflow runtime engine as part of the activity's transition to the Closed state.

(Inherited from StateActivity)

Performs additional processing when the Activities property changes.

(Inherited from CompositeActivity)

Event that occurs before a change being made to the underlying Activities.

(Inherited from CompositeActivity)

Called after changes have been made to the collection Activities of this instance.

(Inherited from CompositeActivity)
RaiseEvent(DependencyProperty, Object, EventArgs)

Raises an Event associated with the specified dependency property.

(Inherited from Activity)
RaiseGenericEvent<T>(DependencyProperty, Object, T)

Raises the event associated with the referenced DependencyProperty.

(Inherited from Activity)
RegisterForStatusChange(DependencyProperty, IActivityEventListener<ActivityExecutionStatusChangedEventArgs>)

Registers the specified DependencyProperty for the status change event.

(Inherited from Activity)
RemoveHandler(DependencyProperty, Object)

Removes an EventHandler from an associated DependencyProperty.

(Inherited from DependencyObject)

Removes a DependencyProperty from the DependencyObject.

(Inherited from DependencyObject)

Writes the Activity to a Stream for persistence.

(Inherited from Activity)
Save(Stream, IFormatter)

Writes the Activity to a Stream for persistence using the custom IFormatter provided for serialization.

(Inherited from Activity)
SetBinding(DependencyProperty, ActivityBind)

Sets the ActivityBind for the specified DependencyProperty.

(Inherited from DependencyObject)
SetBoundValue(ActivityBind, Object)

Sets the value of the target ActivityBind.

(Inherited from DependencyObject)
SetReadOnlyPropertyValue(DependencyProperty, Object)

Sets the value of a DependencyProperty, which is read-only.

(Inherited from DependencyObject)
SetValue(DependencyProperty, Object)

Sets the value of the DependencyProperty to the object.

(Inherited from DependencyObject)
SetValueBase(DependencyProperty, Object)

Sets the value of the DependencyProperty to the specified Object, bypassing the SetValue(DependencyProperty, Object).

(Inherited from DependencyObject)

Provides a string that represents this instance.

(Inherited from Activity)

Informs the run-time tracking infrastructure of pending tracking information.

(Inherited from Activity)
TrackData(String, Object)

Informs the run-time tracking infrastructure of pending tracking information.

(Inherited from Activity)

Called by the workflow runtime engine when an activity transitions into the Closed state from the Initialized state.

(Inherited from CompositeActivity)
UnregisterForStatusChange(DependencyProperty, IActivityEventListener<ActivityExecutionStatusChangedEventArgs>)

Un-registers the specified DependencyProperty for the status change event.

(Inherited from Activity)



Occurs when the activity execution is canceled.

(Inherited from Activity)

Occurs when an Activity has completed execution.

(Inherited from Activity)

Occurs when running a compensation method on the Activity.

(Inherited from Activity)

Occurs when the Activity is run.

(Inherited from Activity)

Occurs when an exception is raised during the running of the instance.

(Inherited from Activity)

Occurs when the ActivityExecutionStatus of a running Activity changes.

(Inherited from Activity)

Explicit Interface Implementations


Represents the method that handles the Disposed event of a component.

(Inherited from DependencyObject)

Applies to

See also