Export (0) Print
Expand All
0 out of 5 rated this helpful - Rate this topic

Flowchart Workflows

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

A flowchart is a well-known paradigm for designing programs. The Flowchart activity is typically used to implement non-sequential workflows, but can be used for sequential workflows if no FlowDecision nodes are used.

Flowchart Workflow Structure

A Flowchart activity is an activity that contains a collection of activities to be executed. Flowcharts also contain flow control elements such as FlowDecision and FlowSwitch that direct execution between contained activities based on the values of variables.

Types of Flow Nodes

Different types of elements are used depending on the type of flow control required when the element executes. Types of flowchart elements include:

  • FlowStep - Models one step of execution in the flowchart.

  • FlowDecision - Branches execution based on a Boolean condition, similar to If.

  • FlowSwitch – Branches execution based on an exclusive switch, similar to Switch.

Each link has an Action property that defines a ActivityAction that can be used to execute child activities, and one or more Next properties that define which element or elements to execute when the current element finishes execution.

Creating a Basic Activity Sequence with a FlowStep Node

To model a basic sequence in which two activities execute in turn, the FlowStep element is used. In the following example, two FlowStep elements are used to execute two activities in sequence.

  <Assign DisplayName="Get Name">
      <OutArgument x:TypeArguments="x:String">[result]</OutArgument>
      <InArgument x:TypeArguments="x:String">["User"]</InArgument>
        <WriteLine Text="[&quot;Hello, &quot; &amp; result]"/>

Creating a Conditional Flowchart with a FlowDecision Node

To model a conditional flow node in a flowchart workflow (that is, to create a link that functions as a traditional flowchart's decision symbol), a FlowDecision node is used. The Condition property of the node is set to an expression that defines the condition, and the True and False properties are set to FlowNode instances to be executed if the expression evaluates to true or false. The following example shows how to define a workflow that uses a FlowDecision node.

    <Read Result="[s]"/>
        <IsEmpty Input="[s]" />
            <Write Text="Empty"/>
            <Write Text="Non-Empty"/>

Creating an Exclusive Switch with a FlowSwitch Node

To model a flowchart in which one exclusive path is selected based on a matching value, the FlowSwitch node is used. The Expression property is set to a Activity with a type parameter of Object that defines the value to match choices against. The Cases property defines a dictionary of keys and FlowNode objects to match against the conditional expression, and a set of FlowNode objects that define how execution should flow if the given case matches the conditional expression. The FlowSwitch also defines a Default property that defines how execution should flow if no cases match the condition expression. The following example demonstrates how to define a workflow that uses a FlowSwitch element.

      <FlowStep x:Key="Red">
      <FlowStep x:Key="Blue">
      <FlowStep x:Key="Green">

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft. All rights reserved.