Using Conditions in Workflows 

You can use conditions to control the behavior of your workflow. The runtime engine evaluates a condition, and then acts based on the result of that evaluation.

There are two ways to represent conditions in your workflow:

  • You can express conditions in code by writing a handler that sets the Result property for your condition.

  • You can also express conditions as a declarative condition, which is a CodeBinaryOperatorExpression in your rule file.

You can also use rules to achieve conditional behavior in your workflow by using the PolicyActivity activity. For more information, see Using the PolicyActivity Activity.

Conditional Activities

Several activities that are provided with the Windows Workflow Foundation use conditions:

  • The first IfElseBranchActivity, contained within an IfElseActivity activity, that has a Condition that evaluates to True will be executed.

  • The WhileActivity activity continuously executes any activities contained within it, as long as its condition evaluates to true. The condition is reevaluated at the completion of each loop.

  • The ConditionedActivityGroup continuously executes any activities within it until its condition evaluates to true. Each individual activity within the ConditionedActivityGroup has a When condition. Each activity executes only when the When condition evaluates to true.

  • The ReplicatorActivity completes its execution when its UntilCondition property evaluates to true.

You can also use conditions in custom activities that you create.

NoteNote

Rule conditions and code conditions can refer to public, private, and internal members defined on your workflow class.

In This Section

How to: Use Conditions Through Code

Workflow Changes to Rule Conditions

Workflow Changes to Rule Conditions

CodeDom Types Supported by Windows Workflow Foundation

See Also

Reference

ConditionedActivityGroup
IfElseBranchActivity
PolicyActivity
ReplicatorActivity
WhileActivity
System.Workflow.Activities.Rules

Concepts

Using the PolicyActivity Activity

Other Resources

Developing Workflows

Footer image

Send comments about this topic to Microsoft.