Task initialization & shut-down

For an overview of tasks please see: Task: overview.

Task initialization sequence

The initialization for the task hierarchy is handled by the task constructor and Task.Startup() as depicted in the following sequence diagram:


The initialization is broken into four main phases:
  1. Create() - task instances are created and their properties set
  2. Connect() - task instances make connections to each other through their connection points
  3. OnInitialize() - task instances' internal state is initialized
  4. OnBeginExecution() - task instances are given the 'go' signal to start processing

In each of these phases, each task instance performs initialization for itself before calling recursively into its sub-task instances to initialize them.

The phases are separated like this because subsequent phases depend on the completion of previous phases for all task instances. For example, it is not possible to connect two tasks together until both have been created so task connection cannot occur after each task creation.


During creation, the base Task class sets up Name, Dimensions and the additional specific properties. The derived Task class is responsible for creating any sub-tasks and adding them to the SubTasks collection. When these sub-tasks are created they are passed a reference to their parent task that allows them to navigate up the hierarchy.


The responsibility for creating connections is left to the derived Task class. This is because it is the derived task class that owns the connection points between which the connections are made. The derived class creates connections between pairs of connection points and passes all these connections to the AcceptConnections() method in the base Task class, where connections are filtered according to the TaskManager's policy and wrapped in a LocatedConnection that records whether they are outgoing (Local) or incoming (Remote).


By default, nothing is done during initialization other than invoking the OnInitialize() method of every task instance recursively. It is up to the derived task class to override OnInitialize() to perform specific initialization work. The OnInitialize() method is a good place to insert code that runs as late in the start-up cycle as possible but still within a single-threaded context.

Begin Execution

By default, nothing is done during begin execution other than invoking the OnBeginExecution() method of every task instance recursively. It is up to the derived task class to override OnBeginExecution() to handle this event appropriately. The OnBeginExecution() method is the place to start processing within a task instance.

Task shut-down

A task is shut down by calling its OnEndExecution() method. This results in all the decendents of that task having their OnEndExecution() method called recursively.

It is up to the deriving task class to implement suitable shut-down logic in their overridden OnEndExecution() method.

Last edited Aug 30, 2012 at 10:07 AM by jaorme, version 11


No comments yet.