Before reading this article, read the blog of WF wxwinter: Workshop.
Repeat wxwinter's blog post:
While and replicator can re-execute its sub-activity, while and replicator do not reset it to the Initial State each time they reuse the activity. Instead, the original activity is cloned, and each cloned activity is managed separately. It does not interfere with other cloned activities. Each cloned activity must have its own AEC to manage the status.
There is no problem with this description. I haven't made it clear for two reasons:
1. Visibility of the cloned activity.
2. When will the activity be cloned.
Let's start with wxwinter's example 2. The root cause of failure in achieving the expected goal is the visibility of the cloned activity.
In example 1, you can perform ++ operations on the myproperty attribute of the active instance in the process. In the process, you can only see the real active instance of activity1, and it is impossible to see a copy of the activity, therefore, the ++ operation is targeted at the real activity1 activity instance. In Example 2, because the ++ operation on the myproperty property of the active instance is blocked in activitylibrary, The ++ operation during running is performed on the copy of the activity, so it does not affect the real active instances.
We often need to block the activitylibrary comrades to pay attention to the need to use this. parent. getactivitybyname (this. name) to get the real activity instance. getactivitybyname is used to return the activity instance of the current activity and its sub-running activity based on the specified type name.
Question 2: When to clone an activity? In a serial condition, clone the activity before each execution sequence. The evidence is used in the copy activity.Code:
Private void codeactivityappsexecutecode (Object sender, eventargs E)
{
Activity1 a1 = This. Parent. getactivitybyname (this. Name) as activity1;
A1.myproperty ++;
Console. writeline (myproperty );
}
The myproperty value of the copy is also changed.
In parallel, all the data is cloned at the beginning.