Share via


State Machine Markup Workflow Sample

Download 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

  1. Right-click the project, point to Add, and then select New Item.

  2. 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

  1. Download the sample by clicking Download Sample.

    This extracts the sample project to your local hard disk.

  2. Click Start, point to Programs, point to Microsoft Windows SDK, and then click CMD Shell.

  3. Go to the source directory of the sample.

  4. At the command prompt, type MSBUILD <Solution file name>.

To run the sample

  1. 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.

See Also

Other Resources

Using Workflow Markup
State Machine Workflows
Workflow Authoring Styles
Markup Samples

© 2007 Microsoft Corporation. All rights reserved.