Understanding the Activity Execution Context
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).
An AEC can only be completed when its associated activity is in the Closed or Initialized state.
An activity can only close 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.