0
votes

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.

1

1 Answers

1
votes

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.