Partager via


Task 1: Create the Simple Order Form Workflow

In this task, you create a basic state machine workflow. You also add the three states that are used in the OrderProcessingWorkflow state machine:

  • The WaitingForOrder state idles until a certain event is raised by the Simple Order Form application.

  • The OrderProcessing state simulates the processing of the order.

  • The OrderCompleted state closes the order.

You provide the application logic for these states in later tasks.

Note

Although you are encouraged to follow the exercises in a linear manner, it is not required. You can start this exercise by opening the sample project and proceeding to the steps in the following section.

To create the state machine workflow project

  1. In Solution Explorer, right-click the StateMachineHost solution, click Add and New Project. Select Visual C#, Workflow, State Machine Workflow Library and change its name to StateMachineWorkflow.

  2. Close the Workflow1.cs [Design] document, right-click Workflow1.cs under the StateMachineWorkflow project in Solution Explorer, and select Rename. Rename the class OrderProcessingWorkflow.cs and confirm that all references to the class should be renamed. This class represents the workflow used for this solution and contains the business logic used by the application.

    The next step is to add a reference to the workflow project to the host project, so that the host project can create the classes defined in the workflow project. Right-click the StateMachineHost project and select Add Reference. Select the Projects tab, select StateMachineWorkflow, and select OK.

To create the state activities

  1. Open the OrderProcessingWorkflow class. The workflow should open in the designer and show one State activity, Workflow1InitialState. Delete this initial state and drag three State activities onto the designer space. Name the activities WaitingForOrderStateActivity, OrderProcessingStateActivity, and OrderCompletedStateActivity by changing the Name setting in the Properties pane when the states are selected. These classes represent the distinct states used in the workflow for tracking the steps performed while processing the order.

  2. Select the workflow design surface to select the workflow itself and set the InitialStateName to WaitingForOrderStateActivity. This should clear the red exclamation point at the top-right corner of the workflow designer, and assign the WaitingForOrderStateActivity activity as the activity to be executed when the state machine starts. Set the CompletedStateName to OrderCompletedStateActivity. This defines the OrderCompletedStateActivity object as the last state in the state machine. The state machine exits when this activity completes.

Compiling the Code

For more information about compiling your code, see Compiling the Code.

In Task 2: Define the IOrderingService Interface, you define the interface and a class that is used to pass data from the host application to the state machine workflow when a new order is submitted.

See Also

Reference

StateMachineWorkflowActivity
CanModifyActivities

Concepts

State Machine Workflows

Other Resources

Task 2: Define the IOrderingService Interface
Tutorial: Create a State Machine Workflow
Ordering State Machine
Simple State Machine

Copyright © 2007 by Microsoft Corporation. All rights reserved.
Last Published: 2010-03-04