Export (0) Print
Expand All

StateActivity Class

Represents a state in a StateMachineWorkflowActivity.

Namespace:  System.Workflow.Activities
Assembly:  System.Workflow.Activities (in System.Workflow.Activities.dll)

[ToolboxBitmapAttribute(typeof(StateActivity), "Resources.StateActivity.png")]
[ComVisibleAttribute(false)]
[ActivityValidatorAttribute(typeof(StateActivityValidator))]
public class StateActivity : CompositeActivity

The StateActivity represents a State in a StateMachineWorkflowActivity. State activities could contain one or more EventDrivenActivity, or StateActivity classes, one StateInitializationActivity class, and one StateFinalizationActivity class. SetState activities are used inside an EventHandlersActivity and StateInitializationActivity to move the state of the workflow.

When a StateActivity is executing, the only events that can be received are the events that can be handled by the EventDrivenActivity activities in the StateActivity and also the EventDrivenActivity activities attached to the enclosing StateActivity activities and the root Activity.

When the StateActivity starts running, the StateActivity will check to see whether a StateInitializationActivity activity is present or not. The StateActivity can have zero or one StateInitializationActivity activity. If a StateInitializationActivity activity is present the StateInitializationActivity will be executed. As soon as the StateInitializationActivity activity finishes, the StateActivity blocks events so that the StateActivity only receives events that can be handled by its EventDrivenActivity activities.

The StateActivity is a CompositeActivity, meaning the StateActivity activity can contain other activities.

The following code example shows how to create a new instance of the StateActivity class and use it implement a simple state machine to transition between 3 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 
//  
this.WhileLoop.Activities.Add(this.Parallel);
codecondition1.Condition += new System.EventHandler<System.Workflow.Activities.ConditionalEventArgs>(this.WhileCondition);
this.WhileLoop.Condition = codecondition1;
this.WhileLoop.Name = "WhileLoop";
//  
// Parallel 
//  
this.Parallel.Activities.Add(this.Sequence1);
this.Parallel.Activities.Add(this.Sequence2);
this.Parallel.Name = "Parallel";

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0

Community Additions

ADD
Show:
© 2014 Microsoft