Datasheet
Chapter 1: Workfl ow Programming Principles
22
Listing 1-8 (continued )
}
void Activity_Closed(object sender,
ActivityExecutionStatusChangedEventArgs e)
{
e.Activity.Closed -= this.Activity_Closed;
foreach (Activity activity in this.EnabledActivities)
{
if (activity.ExecutionStatus !=
ActivityExecutionStatus.Initialized ||
activity.ExecutionStatus != ActivityExecutionStatus.Closed)
return;
}
ActivityExecutionContext executionContext =
sender as ActivityExecutionContext;
executionContext.CloseActivity();
}
}
}
The ParallelActivity flow control activity, like any other flow control activity, inherits from the
CompositeActivity base class. This is because every flow control activity is a composite activity. As
shown in Listing 1 - 8 , the Execute method of ParallelActivity takes these steps:
1. It returns ActivityExecutionStatus.Closed to inform the workflow run time it has completed its
execution if ParallelActivity contains no child activities. As mentioned earlier, the execution
methods of an activity must inform the workflow run time every time its execution status
changes. There are two types of execution methods. The first type contains the Execute, Cancel,
and HandleFault methods, which return a value of the ActivityExecutionStatus enumeration
type. These methods must notify the workflow run time of their execution status changes by
returning the appropriate ActivityExecutionStatus enumeration value. The second type contains
event handlers that are registered for events such as the QueueItemAvailable event of a
workflow queue or the Closed event of a child activity. Because these event handlers return
void, they must use the ClosedActivity method of the ActivityExecutionContext when the
respective activity needs to transition to the Closed state. Keep in mind that the workflow run
time does not consider a workflow completed until every single activity is in either Initialized or
Closed state:
if (this.EnabledActivities.Count == 0)
return ActivityExecutionStatus.Closed;
2. It iterates through the child activities of ParallelActivity, registers the Activity_Closed method as
event handler for the Closed event of each enumerated child activity, and invokes the
ExecuteActivity method on the ActivityExecutionContext object for each enumerated child
activity to schedule the child activity ’ s Execute method with the WF scheduler for execution:
c01.indd 22c01.indd 22 8/25/08 4:02:57 PM8/25/08 4:02:57 PM