Condividi tramite


Understanding the Activity Execution Context

An ActivityExecutionContext (AEC) is the execution environment that is created for an activity when the host application calls the Start method.

The AEC provides a composite activity with the ability to execute (ExecuteActivity) or cancel (CancelActivity) a child activity. It can also close itself through the CloseActivity method. These are the only execution status changes that a parent activity can control through the AEC. All other activity states are controlled by the workflow runtime engine.

The AEC has a property called ExecutionContextManager that enables it to generate new AECs. These AECs are generated every time a parent activity, such as a WhileActivity activity, ReplicatorActivity activity, or ConditionedActivityGroup activity, runs its child activities more than once. Each iteration creates a cloned activity with its own AEC, so that these various instances of child activities can run independently (and possibly in parallel in the case of the ReplicatorActivity activity).

In addition, the ActivityExecutionContextManager recovers persisted contexts and completed contexts in which all activities are either in the Closed or Initialized states with optional persistence.

Since iterated activities are clones of a template object, changes made to them will not affect the template activity, and will not persist to new iterations of that activity. Also, iterated activities (the actual instances of ReplicatorActivity children, or activities contained within a WhileActivity or ConditionedActivityGroup) cannot be accessed by the name that they are defined in the workflow, or by using GetActivityByName from the parent activity. Instead, they must be accessed via the sender or e.Activity parameter of the containing event handler. So, instead of accessing a DelayActivity instance that is defined as a child activity of a WhileActivity activity directly:

this.delayActivity1 

it must be accessed via a parameter of the executing event handler:

((DelayActivity)sender

Note

An AEC can be completed only when its associated activity is in the Closed or Initialized state.

An activity can close only when all spawned execution contexts (CreateExecutionContext) have been completed (CompleteExecutionContext). Violation of this behavior causes an exception to be thrown by the workflow runtime engine.

See Also

Concepts

Understanding the Activity State Model
Using the ReplicatorActivity Activity
Using the ConditionedActivityGroup Activity
Using the WhileActivity Activity
Using the StateActivity Activity
Using the EventHandlersActivity Activity

Other Resources

Windows Workflow Foundation Activities