Simple State Machine Sample
This sample demonstrates the use of a state machine workflow to implement a simple state machine with three states. The state machine transitions from the Start state to State 1, and then from State 1 to State 2.
A state machine workflow consists of states. Each state is composed of one or more EventDrivenActivity activities. Each StateActivity can contain one StateInitializationActivity , one or more EventDrivenActivity activities and one StateFinalizationActivity. It can contain any or all of these activites.
Each state machine workflow has two properties called InitialStateName and CompletedStateName. When an instance of the state machine workflow is created, it is put into the InitialStateName. When the state machine reaches the CompletedStateName, it finishes execution.
In this sample, the Start state is the InitialStateName and has an EventDrivenActivity. That EventDrivenActivity has a DelayActivity activity as its first activity. The delay activity has a delay time-out of five seconds. The EventDrivenActivity also has a SetStateActivity activity to transition to State 1.
State 1 is similar to the Start state and has an EventDrivenActivity with a delay activity in it. The delay time-out is set at five seconds. The EventDrivenActivity also has a set state activity that transitions to State 2.
State 2 is the completed state. When the transition is made to State 2, the state machine stops executing.
To build the sample
Download the sample by clicking Download Sample in this topic.
This extracts the sample project to your local hard disk.
Click Start, point to Programs, point to Microsoft Windows SDK, and then click CMD Shell.
Go to the source directory of the sample.
At the command prompt, type MSBUILD <Solution file name>.
To run the sample
- In the SDK Command Prompt window, run the .exe file in the SimpleStateMachineWorkflow\bin\debug folder (or the SimpleStateMachineWorkflow\bin folder for the Visual Basic version of the sample), which is located below the main folder for the sample.of the sample.
Using the State Activity
Using the StateInitialization Activity
Using the SetState Activity
Creating a State Machine Workflow
State Machine Workflows
Basic Workflows Samples
Windows Workflow Foundation Samples
© 2007 Microsoft Corporation. All rights reserved.