State Machine Markup Workflow Sample
This sample includes a simple state machine workflow that is created as markup (XAML) with code-beside. It uses 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 CompletedState.
A state machine workflow consists of states. Each state is composed of one or more event handlers. Each event handler must contain a delay or an IEventActivity as the first activity. Each event handler can also contain a SetStateActivity activity that is used to transition from one state to another.
Each state machine workflow has two properties: InitialStateName and CompletedStateName. When an instance of the state machine workflow is created, it is put into the InitialStateName property. When the state machine reaches the CompletedStateName property, it finishes execution.
In this sample, the Start state is the InitialStateName and has an event handler. That event handler has a DelayActivity activity as its first activity. The DelayActivity activity has a delay time-out of two seconds. The event handler also has a SetStateActivity to transition to State 1.
State 1 is similar to the Start state and has an event handler with a delay activity in it. The delay time-out is set at two seconds. The event handler also has a set state activity that transitions to State 2.
CompletedState is the final state. When a transition is made to CompletedState, the state machine stops executing.
To create a state machine workflow as markup
Right-click the project, point to Add, and then select New Item.
Select State Machine Workflow (with code separation).
After the workflow is created, you can add activities and use the workflow in a project just like you use a code-only workflow.
To build the sample
Download the sample by clicking Download Sample.
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 StateMachineMarkupWorkflow\bin\debug folder (or the StateMachineMarkupWorkflow\bin folder for the Visual Basic version of the sample), which is located below the main folder for the sample.
© 2007 Microsoft Corporation. All rights reserved.