Search

Search:

Namespace:

Search Result
.
          • ReplicatorActivity
.

Property of a ReplicatorActivity to use with an UntilCondition to check is the replicator is done executing.

.

http://msdn.microsoft.com/en-us/library/system.workflow.activities.replicatoractivity.allchildrencomplete.aspx

.

ReplicatorActivity

.
Summary
Used in the ReplicatorActivity and is either Sequence or Parallel
.

ReplicatorActivity

.

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 can be used in two ways, in Sequence or in Parallel. Use the ExecutionType property to determine the way it is used. If use in sequence the CurrentIndex can be used to see which item we are executing as found in the CurrentChildData. Note that when executing in parallel the CurrentIndex always points to the last item.

.

Check UntilConditionAndTheReplicatorActivity for more information.

.

The ReplicatorActivity is similar to a For Each statement in code. It is also same as the while activity. There are two types of execution type Sequential type and Parallel type.

.
Warning
.

Replicator Activity runs multiple instances of a child activity.The ReplicatorActivity activity can create and execute an arbitrary number of identical child activities either sequentially or in parallel.

.

Gets or sets a completion condition that indicates when the ReplicatorActivity or the ConditionedActivityGroup should finish.

.

Check UntilConditionAndTheReplicatorActivity for more information.

.
Summary
Using a ReplicatorActivity with an UntilCondition can be a bit of a chalenge
.

The ReplicatorActivity is one of the more interesting Workflow Foundation activities to work with when you have a collection of data and want to iterate over each item. Basically just think of it as a For Each statement in regular code.

.

.
  <ReplicatorActivity x:Name="replicatorActivity1"
.
    <ReplicatorActivity.UntilCondition>
.
    </ReplicatorActivity.UntilCondition>
.
  </ReplicatorActivity>
.
        Dim replicator As ReplicatorActivity = sender
.
        Dim replicator As ReplicatorActivity = sender
.
        Dim replicator As ReplicatorActivity = sender
.

Using the without an UntilCondition is actually quite simple. The main thing to be aware of the ExecutionType property. In this case I didn't set it and it defaults to Sequence. This means that each iteration comes after the next iteration and we can use the CurrentIndex and CurrentChildData to retrieve the piece of data we are working with. When we set the ExecutionType to Parallel the ReplicatorActivity behaves very different. In that case each branch is started at the same time so the CurrentIndex, which is scoped to the ReplicatorActivity, doesn't help you. In fact it will return the last item of the collection every time you try.

.

In the case of parallel execution the way to get at the data is the ChildInitialized event. This event has a parameter of type ReplicatorChildEventArgs which in turn contains a property InstanceData which is the data this iteration is going to work with. its your responsibility to pass this InstanceData on to the activity inside the ReplicatorActivity. The usual thing to do here is create a custom, possibly sequence, activity with an extra property to hold the data and store it there in the ChildInitialized event.

.

There are a few interesting, and unexpected, thing to be a aware of when you use an UntilCondition with a ReplicatorActivity. When I run this simple test workflow I receive the following output:

.

.
  1. The first time the UntilCondition is called is before the first ChildInitialized event and when we retrieve the current data it actually returns the last item. As far as I can tell there is no standard way to see this is case so if could be a problem you need to take care of it yourself. As far as I am concerned this is a serious shortcoming of the ReplicatorActivity
.
  1. The UntilCondition fires after and not before each loop is executed. Basically this means it is easy to use the execution result of an iteration and decide to stop further iterations but hard to prevent all remaining iteration, including the current, based on the input data. Again you would need to add some conditional logic inside the ReplicatorActivity. No problem and actually quite a nice behavior but something to be aware of.
.
  1. The ReplicatorActivity never stops if you don't tell it to. This is the behavior I most dislike with the ReplicatorActivity. Instead of just stopping and continuing with the next activity when all data is processed it just stops . Now this isn't the case when you don't have an UntilCondition, in that case every item is processed and when done it proceeds with the next activity just as you would expect. No with an UntilCondition you are responsible for stopping and to do so the UntilCondition is actually called one more time after the last item has been processed. The thing to check for is the AllChildrenComplete property of the ReplicatorActivity. When this is true all the data has been processed and you are responsible for stopping the ReplicatorActivity. Now this might not be hard but it always is a major point of confusion and, I presume, catches everyone at least the first time. And worse I can see no benefit at all for this behavior as the ReplicatorActivity just stops and the next activity is never scheduled. As far as I am concerned this is a big "bug" in the behavior of the ReplicatorActivity.
.

.

A WhileActivity can only contain a single child activity, the same is true for a ReplicatorActivity. However a IfElseActivity and a ListenActivity can contain multiple child activities. Now the difference doesn't matter much as the single activity in the WhileActivity or ReplicatorActivity can be a SequenceActivity which in turn can contain multiple children but still it's confusing.