Datasheet

Chapter 1: Work ow Programming Principles
19
SequenceActivity activity returns ActivityExecutionStatus.Closed to inform the workflow run time that
it has completed its execution. A SequenceActivity activity without any child activities is the WF
equivalence of an empty C# { } statement block.
If the EnabledActivities collection is not empty that is, if the SequenceActivity activity or logical { }
flow control contains logical program statements or activities then the Execute method takes the
following steps to execute the first child activity or logical program statement (keep in mind that
the SequenceActivity activity executes its child activities one activity at a time):
1. It accesses the first child activity or logical program statement:
Activity activity = this.EnabledActivities[0];
2. It registers an event handler named Activity_Closed for the Closed event of the first child
activity:
activity.Closed += Activity_Closed;
3. It invokes the ExecuteActivity method on the ActivityExecutionContext object that represents
the execution context within which the Execute method is executing to schedule the first child
activity for execution:
executionContext.ExecuteActivity(activity);
Note that the SequenceActivity activity does not directly invoke the Execute method of its child
activity. Instead, it invokes the ExecuteActivity method to schedule the Execute method of its
child activity for execution. As discussed earlier, scheduling a method for execution basically
adds a work item to the WF scheduler. This work item is basically nothing but a delegate that
encapsulates the Execute method of the first child activity. In order to ensure that no one can di-
rectly call the Execute method of an activity, this method is marked as protected internal.
4. Finally, the method returns ActivityExecutionStatus.Executing to inform the workflow run time
that it hasn t completed its execution yet:
return ActivityExecutionStatus.Executing;
As just discussed, the Execute method of the SequenceActivity activity schedules the Execute method of
its first child activity with the WF scheduler for execution. At some point, the WF scheduler finally
invokes the Execute method of the first child activity. The execution logic of the first child activity may
require the activity to suspend its execution indefinitely until the required data is deposited into the
appropriate workflow queue, at which point the activity resumes its execution. This process may be
repeated any number of times until the first child activity finally completes its execution, at which point
the activity raises its Closed event and consequently the Activity_Closed event handler that the
SequenceActivity activity has registered for this event is scheduled with the WF scheduler for execution.
When the WF scheduler finally invokes the Activity_Closed event handler, it passes an
ActivityExecutionContext object as its first argument. This object basically represents the execution
context within which this event handler must execute.
c01.indd 19c01.indd 19 8/25/08 4:02:56 PM8/25/08 4:02:56 PM