Using the WhileActivity Activity

The WhileActivity activity iteratively executes a single child activity as long as its Condition property is true. A rule condition or a code condition that is associated with the Condition property is evaluated before each iteration of the WhileActivity loop. If the condition evaluates to true, the child activity is executed. If the condition evaluates to false, the child activity is not executed, and the WhileActivity activity finishes.

Because the WhileActivity activity can only contain a single child activity, you might want to use a SequenceActivity activity or a ParallelActivity activity inside the WhileActivity to contain multiple activities.

When a child activity is executed more than once, a separate instance of the activity is created for each iteration. This allows the instances to execute independently (and potentially in parallel, as in the case of a ReplicatorActivity activity). As a consequence, the definition of the child activity in the activity tree (referred to as the template) is never executed and is always in the Initialized state. Access to the running instances of the template is provided by the composite activity that is the parent of the template. For example, in the case of the WhileActivity activity, there is always one active instance, and the DynamicActivity property retrieves this instance.

For more information about conditions, see Using Conditions in Workflows.

For more information, see the WhileActivity class of the System.Workflow.Activities namespace in the Windows Workflow Foundation Class Library reference.

See Also




Using Conditions in Workflows
Using the SequenceActivity Activity
Using the ParallelActivity Activity
Rules and Conditions Overview

Other Resources

While and Parallel Sample
Changing Rules Sample
Windows Workflow Foundation Activities