Export (0) Print
Expand All

CompositeActivity Class

Derivative of Activity that is the base class for all activities that contain other activities. A CompositeActivity is responsible for managing the execution of its child activities.

Namespace:  System.Workflow.ComponentModel
Assembly:  System.Workflow.ComponentModel (in System.Workflow.ComponentModel.dll)

[ActivityValidatorAttribute(typeof(CompositeActivityValidator))]
[ContentPropertyAttribute("Activities")]
[ActivityCodeGeneratorAttribute(typeof(CompositeActivityCodeGenerator))]
public class CompositeActivity : Activity

A CompositeActivity manages the execution of its child activities using ActivityExecutionContext class methods and events defined on the Activity class. For example, a child activity is scheduled for execution using the ExecuteActivity of ActivityExecutionContext. A CompositeActivity activity can be notified when a child activity completes its execution by subscribing to the Closed event defined on Activity.

The workflow runtime enforces certain constraints on CompositeActivity execution, the most fundamental of which is that a CompositeActivity activity cannot move to the Closed state if any child activities are still in a Executing, Canceling, Compensating, or Faulting, state.

This example shows a basic CompositeActivity that executes its first child activity for execution. When the child activity moves to the Closed state, the composite activity is notified and then completes its execution.

public class HasOneChildActivity : CompositeActivity
{
    protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
    {
        Activity child = this.EnabledActivities[0];
        child.Closed += this.ChildClosed;
        executionContext.ExecuteActivity(child);

        return ActivityExecutionStatus.Executing;
    }

    void ChildClosed(object sender, ActivityExecutionStatusChangedEventArgs e)
    {
        e.Activity.Closed -= this.ChildClosed;
        ActivityExecutionContext executionContext = sender as ActivityExecutionContext;

        executionContext.CloseActivity();
    }
}

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0

Community Additions

ADD
Show:
© 2014 Microsoft