lysergic-acid
lysergic-acid

Reputation: 20050

Accessing results of nested tasks from the parent task

I am currently exploring TPL and i am wondering if the following scenario is possible:

I'd like to create a nested structure with a single parent and multiple "child" tasks under it.

The structure is similar to this:

Parent Task
    |
    |-- Child Task A
    |-- Child Task B 
    |-- ...

I would like the parent task to wait for all child tasks to complete, and access their results (in order to determine the result of itself).

I could not find any valuable information of nesting tasks and accessing their result from the parent.

Upvotes: 0

Views: 771

Answers (1)

David Tischler
David Tischler

Reputation: 2682

One way would be to use the static method Task.WaitAll in the parent-task to wait for all child tasks to complete, then check their individual Status- and Result-properties.

If there is no work at all for the parent-task before all child-tasks are completed, you could restructure it and use TaskFactory.ContinueWhenAll to start a new task once all child-tasks are completed. This can then access the individual results.

Upvotes: 1

Related Questions