Share via


StateMachine Scenario Using a Combination of FlowChart and Pick

This topic applies to Windows Workflow Foundation 4 (WF4).

This sample demonstrates how to implement a simple stopwatch scenario using a combination of the Flowchart and Pick activities. It uses Receive and Send within the Pick activity to listen for stopwatch events.

Sample Details

The following table lists the projects in this sample.

Project Name

Description

StopWatchService

This project contains the implementation of a state machine for the stopwatch sample using a combination of the Flowchart and Pick activities.

The Pick activity has 3 PickBranch statements within the Branches property that listen for GetStart, GetStop and GetOff events. Based on the incoming event, the triggers for one of the branches activate and the corresponding Action is triggered. In the Action property, there is a Switch statement that evaluates whether the transition is a legitimate transition and if it is, the currentState property is updated to the transitioning state and sent to the client.

The FlowDecision activity at the end of the Flowchart evaluates the currentState property to determine whether the state is terminal. If it is, the workflow ends; otherwise control loops back to the start of the Pick activity where the workflow waits for more stopwatch events.

StopWatchClient

This is a simple sequential workflow console application that sends various stopwatch events with simple Send or Receive activity combinations.

To use this sample

  1. Using Visual Studio 2010, open StateMachineWithPick.sln solution file.

  2. To build the solution, press CTRL+SHIFT+B.

  3. Start the StopWatchService.exe from Windows Explorer as an administrator by right clicking the .exe file and selecting Run as administrator.

    1. Navigate to the StateMachineWithPick\CS\StopWatchService\bin\Debug folder.

    2. Right-click the StopWatchService.exe file and select Run as administrator.

  4. Start the StopWatchClient client application from within Visual Studio 2010.

    1. In Solution Explorer, select the StopWatchClient project and right-click Set as StartUp Project.

    2. To run the solution, press CTRL+F5.

  5. Switch back to the console window for the StopWatchService.exe to view the state transitions.

Dd807384.Important(en-us,VS.100).gif Note:
The samples may already be installed on your computer. Check for the following (default) directory before continuing.

<InstallDrive>:\WF_WCF_Samples

If this directory does not exist, go to Windows Communication Foundation (WCF) and Windows Workflow Foundation (WF) Samples for .NET Framework 4 to download all Windows Communication Foundation (WCF) and WF samples. This sample is located in the following directory.

<InstallDrive>:\WF_WCF_Samples\WF\Scenario\StateMachineWithPick