This documentation is archived and is not being maintained.

StateActivity Class

Represents a state in a StateMachineWorkflowActivity.

Namespace: System.Workflow.Activities
Assembly: System.Workflow.Activities (in system.workflow.activities.dll)

[ComVisibleAttribute(false)] 
public class StateActivity : CompositeActivity
/** @attribute ComVisibleAttribute(false) */ 
public class StateActivity extends CompositeActivity
ComVisibleAttribute(false) 
public class StateActivity extends CompositeActivity
Not applicable.

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.

public partial class StateMachineWorkflow
{
    [System.Diagnostics.DebuggerNonUserCode()]
    private void InitializeComponent()
    {
        this.CanModifyActivities = true;
        this.setCompletedState = new System.Workflow.Activities.SetStateActivity();
        this.code2 = new System.Workflow.Activities.CodeActivity();
        this.state1Delay = new System.Workflow.Activities.DelayActivity();
        this.setState1 = new System.Workflow.Activities.SetStateActivity();
        this.code1 = new System.Workflow.Activities.CodeActivity();
        this.startStateDelay = new System.Workflow.Activities.DelayActivity();
        this.eventDriven2 = new System.Workflow.Activities.EventDrivenActivity();
        this.eventDriven1 = new System.Workflow.Activities.EventDrivenActivity();
        this.CompletedState = new System.Workflow.Activities.StateActivity();
        this.state1 = new System.Workflow.Activities.StateActivity();
        this.StartState = new System.Workflow.Activities.StateActivity();
        // 
        // setCompletedState
        //
        this.setCompletedState.Name = "setCompletedState";
        this.setCompletedState.TargetStateName = "CompletedState";
        // 
        // code2
        // 
        this.code2.Name = "code2";
        this.code2.ExecuteCode += new System.EventHandler(this.Code2Handler);
        // 
        // state1Delay
        //
        this.state1Delay.Name = "state1Delay";
        this.state1Delay.TimeoutDuration = System.TimeSpan.Parse("00:00:02");
        // 
        // setState1
        // 
        this.setState1.Name = "setState1";
        this.setState1.TargetStateName = "state1";
        // 
        // code1
        // 
        this.code1.Name = "code1";
        this.code1.ExecuteCode += new System.EventHandler(this.Code1Handler);
        // 
        // startStateDelay
        // 
        this.startStateDelay.Name = "startStateDelay";
        this.startStateDelay.TimeoutDuration = System.TimeSpan.Parse("00:00:05");
        // 
        // eventDriven2
        // 
        this.eventDriven2.Activities.Add(this.state1Delay);
        this.eventDriven2.Activities.Add(this.code2);
        this.eventDriven2.Activities.Add(this.setCompletedState);
        this.eventDriven2.Name = "eventDriven2";
        // 
        // eventDriven1
        // 
        this.eventDriven1.Activities.Add(this.startStateDelay);
        this.eventDriven1.Activities.Add(this.code1);
        this.eventDriven1.Activities.Add(this.setState1);
        this.eventDriven1.Name = "eventDriven1";
        // 
        // CompletedState
        // 
        this.CompletedState.Name = "CompletedState";
        // 
        // state1
        // 
        this.state1.Activities.Add(this.eventDriven2);
        this.state1.Name = "state1";
        // 
        // StartState
        // 
        this.StartState.Activities.Add(this.eventDriven1);
        this.StartState.Name = "StartState";
        // 
        // StateMachineWorkflow
        // 
        this.Activities.Add(this.StartState);
        this.Activities.Add(this.state1);
        this.Activities.Add(this.CompletedState);
        this.CompletedStateName = "CompletedState";
        this.DynamicUpdateCondition = null;
        this.InitialStateName = "StartState";
        this.Name = "StateMachineWorkflow";
        this.CanModifyActivities = false;
    }
    private StateActivity StartState;
    private EventDrivenActivity eventDriven1;
    private SetStateActivity setState1;
    private StateActivity state1;
    private EventDrivenActivity eventDriven2;
    private DelayActivity state1Delay;
    private SetStateActivity setCompletedState;
    private CodeActivity code1;
    private CodeActivity code2;
    private DelayActivity startStateDelay;
    private StateActivity CompletedState;
}

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 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0
Show: