내보내기(0) 인쇄
모두 확장

StateMachineWorkflowActivity 클래스

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

네임스페이스: System.Workflow.Activities
어셈블리: System.Workflow.Activities(system.workflow.activities.dll)

[ComVisibleAttribute(false)] 
public class StateMachineWorkflowActivity : StateActivity
/** @attribute ComVisibleAttribute(false) */ 
public class StateMachineWorkflowActivity extends StateActivity
ComVisibleAttribute(false) 
public class StateMachineWorkflowActivity extends StateActivity
적용할 수 없음.

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

The StateMachineWorkflowActivity is a CompositeActivity, meaning 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, as the name suggests, is the state in which the state machine will be 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. Consider 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.

The following code example shows how to create a new instance of the StateMachineWorkflowActivity class and use it to implement a simple 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.

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;
}

이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

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

Microsoft .NET Framework 3.0은 Windows Vista, Microsoft Windows XP SP2 및 Windows Server 2003 SP1에서 지원됩니다.

.NET Framework

3.0에서 지원

커뮤니티 추가 항목

추가
표시:
© 2015 Microsoft