Datasheet

Chapter 1: Work ow Programming Principles
21
discussed earlier to schedule the execution of the Execute method of the next activity with the
WF scheduler:
else
{
Activity activity = this.EnabledActivities[index];
activity.Closed += this.Activity_Closed;
executionContext.ExecuteActivity(activity);
}
ParallelActivity
As mentioned earlier, one of the great things about WF as a workflow programming language versus a
standard procedural programming language such as C# is that the set of logical flow control constructs
that WF supports are extensible. Another important characteristic of WF as a workflow programming
language versus a standard procedural programming language is that WF supports logical flow control
constructs that have no counterpart in standard procedural programming languages. One of these
logical flow control constructs is the ParallelActivity flow control construct. This flow control construct
executes its containing logical program statements or child activities in parallel. The only way to run
different sets of C# program statements in parallel is to run each set on a separate .NET thread. You
cannot run these sets in parallel on the same thread. WF program statements, conversely, can be
executed in parallel on the same .NET thread. You can think of each WF execution branch as running on
a separate logical thread, where all these logical threads are running on the same .NET thread.
Listing 1 - 8 presents the implementation of the ParallelActivity flow control construct, which is a
simplified version of the implementation of the standard ParallelActivity flow control construct.
Listing 1 - 8: The ParallelActivity flow control construct
using System.Workflow.ComponentModel;
using System.Workflow.Runtime;
using System;
namespace Chapter1
{
public class ParallelActivity : CompositeActivity
{
protected override ActivityExecutionStatus Execute(
ActivityExecutionContext executionContext)
{
if (this.EnabledActivities.Count == 0)
return ActivityExecutionStatus.Closed;
foreach (Activity activity in this.EnabledActivities)
{
activity.Closed += Activity_Closed;
executionContext.ExecuteActivity(activity);
}
return ActivityExecutionStatus.Executing;
(continued)
c01.indd 21c01.indd 21 8/25/08 4:02:57 PM8/25/08 4:02:57 PM