Using the ReplicatorActivity Activity

The ReplicatorActivity activity enables you to create an arbitrary number of instances of a single activity during run time. Each ReplicatorActivity activity can contain only one child activity, but the child can be a composite activity.

By default, the ReplicatorActivity activity finishes when all child activities have finished. You can use the UntilCondition property to stop execution of the ReplicatorActivity before the completion of the child activity instances. For more information about conditions, see Using Conditions in Workflows.


The ReplicatorActivity activity hangs if all the child activities have finished and the UntilCondition property evaluates to false. After the ReplicatorActivity activity has hung in this manner, you can use a workflow change to add a child activity to the ReplicatorActivity activity that will cause the UntilCondition to evaluate to true.

A ReplicatorActivity requires two key pieces of information:

  • The ExecutionType property must be set to Sequential or Parallel. The ExecutionType property indicates whether replicated child activity instances execute in parallel, in which case all instances are created when the ReplicatorActivity activity executes, or sequentially, in which case each instance of the child activity is executed in turn, after the completion of the previous instance.

  • The InitialChildData collection property must be populated to provide the data for each replicate instance of the child activity.

You can implement the Initialized handler, which is raised before the ReplicatorActivity starts executing, to populate the InitialChildData collection property and set the ExecutionType.

You can also specify handlers for the following events to use together with the ReplicatorActivity activity:

  • The ChildInitialized event that is raised each time an instance of the child activity is initialized passes the data from the item in the InitialChildData collection to the actual instance of the child being initialized. ReplicatorChildEventArgs contains the event arguments for this handler.

  • The ChildCompleted event that is raised each time an instance of the child activity finishes. ReplicatorChildEventArgs contains the event arguments for this handler.

  • The Completed event that is raised after the ReplicatorActivity finishes.

When a child activity is executed more than once, a separate instance of the child activity is created for each iteration. This enables the instances to execute independently (and potentially in parallel, as in the case of the ConditionedActivityGroup activity). As a consequence, the definition of the activity in the activity tree (referred to as the template) is never executed and will always be 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 a ReplicatorActivity activity, there might be multiple active instances, so the ReplicatorActivity.DynamicActivities returns a collection of the running instances of the child activity.

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

For a code sample that demonstrates how to use the ReplicatorActivity activity, see Using Replicator.

See Also




Using Conditions in Workflows
Rules and Conditions Overview

Other Resources

Replicator Sample
Windows Workflow Foundation Activities