This project is read-only.

Microsoft.Activities.StateMachine Requirements

As a .NET Developer
I want to create a State Machine without having to learn Windows Workflow Foundation or using the Workflow Designer
So that I can create a simple straightforward state machine using familiar concepts but run it with Windows Workflow Foundation

As a .NET Developer
I want to create a State Machine using a Fluent Interface concept
So that the code is simple to read and easy to maintain

As a WF Developer
I want to create a State Machine using Code that can take advantage of my workflow knowledge
So that I can use activities, extensions, persistence and tracking in a purely code based experience.


Why would you create a state machine like this?
  • A user interface almost always has elements of a state machine
  • To create a UI wizard
  • To model a long running business process

Design Notes

Prototype Example

This prototype code is creating the state machine activity that you build in exercise 1 of the Introduction to State Machine Hands on Lab. For a prototype I wanted to see how it would feel to use an alternate code based API with no workflow concepts at all.

private StateMachine<AtmState, AtmTrigger> CreateStateMachine()
    // Fluent interface for declaring the state machine
    // Enums define the states and transitions
    this.atmStateMachine = new StateMachine<AtmState, AtmTrigger> { DisplayName = "ATM StateMachine" };

    // Use an indexer to refer to the state you want
    // Non workflow developers can use lambda expressions or Action to provide implementation - no need to learn WF
    // AutoTrigger is a null transition
        .Entry(this.Prompt, Activities.Prompts.PleaseWait)

    // When defines a transition that is implemented with a bookmark
        .Entry(this.Prompt, Activities.Prompts.InsertCard)
        .When(AtmTrigger.PowerOff, AtmState.PowerOff);


    return this.atmStateMachine;

Spike Ideas

  • Re-implement the state machine (and model / view model) from the Intro to State Machine Hands On Lab using a code based approach to see how they compare
  • Explore state management and persistence - how can we make a simple state management experience for a non-WF developer who does not want to learn about Variable<T> and context etc.
  • Create a state machine that uses WF activities, tracking, persistence and custom extensions
  • Implement a workflow service using a code based state machine

Last edited Jun 15, 2011 at 1:13 AM by ronjacobs, version 5


YoYoRnd Aug 27, 2012 at 11:26 AM 
Hi Ron, I would like to use WF for test automation. Is there any progress in the coded statemachine thread?
Thank you.

snowmenrui Nov 27, 2011 at 4:06 AM 
Hi Ron,I have a problem that WF4 StateMachine support parallel?or WF4 Flowchart support parallel?