Datasheet
Chapter 1: Workfl ow Programming Principles
28
It invokes the Initialize method on all activities in the new activity branch copy. This
basically does what a C# “ while ” loop does for each iteration. Recall that a C# “ while ” loop
resets all the local variables at the beginning of each iteration. In other words, no residual
effects are carried over from the previous iteration. The only difference is that C# resets the
same local variables, whereas WF creates a new copy of the child activity and its
descendants and calls the Initialize method on the new copy of the child activity and
its descendants.
It returns an ActivityExecutionContext object that represents the child execution context.
2.
It accesses the new copy of the child activity of the WhileActivity activity and registers the
Activity_Closed event handler for the Closed event of this child activity copy:
childExecutionContext.Activity.Closed += Activity_Closed;
The child execution context exposes a property named Activity of the Activity type, which
returns a reference to the new copy of the child activity of the WhileActivity activity.
3. It invokes the ExecuteActivity method on the child execution context, passing in the reference to
the new copy of the child activity of the WhileActivity activity to schedule the Execute method
of the new copy of this child activity for execution:
childExecutionContext.ExecuteActivity(childExecutionContext.Activity);
Note that the Execute method of the WhileActivity activity uses the ExecuteActivity method of
the child execution context as opposed to the global execution context (keep in mind that the
global activity execution context is referenced through the ActivityExecutionContext object
passed into the Execute method of the WhileActivity activity) to schedule the Execute method
of the new copy of the child activity of the WhileActivity activity for execution. This ensures that
the new copy of the child activity is executed within the context of the child execution context as
opposed to the global execution context. This is similar to the C# while loop, where the content
of the while loop is executed in a local context as opposed to the global context:
return ActivityExecutionStatus.Executing;
At some point, the WF scheduler dispatches the work item that encapsulates the Execute method of the
new copy of the child activity of the WhileActivity activity and consequently invokes the Execute
method of the new copy of the child activity, passing in an activity execution context that represents the
new child execution context. This means that the Execute method of the new copy of the child activity
will be executed within the context of the new child execution context. This Execute method in turn may
have to suspend the execution of the new copy of the child activity waiting indefinitely for an external
input before it resumes its execution.
When the new copy of the child activity finally completes its execution and raises the Closed event, the
Activity_Closed event handler of the WhileActivity activity is scheduled for execution. At some point,
the WF scheduler finally invokes the Activity_Closed event handler, passing an
ActivityExecutionContext object that represents the global execution context because all execution
methods of the WhileActivity activity execute within the context of the global execution context. It is
only the execution methods of the new copy of the child activity of the WhileActivity activity that are
executed in the context of the new child execution context.
❑
❑
c01.indd 28c01.indd 28 8/25/08 4:02:59 PM8/25/08 4:02:59 PM