1
votes

I have a list of n tasks that I want to execute in parallel, asyncronously.

Each of the parallel running tasks can have 1 or more nested tasks.

I also need to wait and analyse the return result of each Task. The entire operation is successful only if all tasks execute successfuly (e.g. they return "true").

Effectively, this is a transactional operation where I need to wait for many tasks to complete sucessfully.

The problem is that each task may take 1-3 hours to complete (some tasks may take only minutes, while others take hours) The whole operation might take a full work day.

My questions:

  1. Is this approach feasable and doable using Task Parallel Library?
  2. Also, what happens if one of the tasks times out and fails to report back to the mother task?
  3. Can the library handle such scenarios where tasks are not only nested, but alos take a very long time to complete?

EDIT: I found this blog post about cancelling tasks, especially long running ones. Maybe it useful to others, too.

1
Is a SQL transaction (or any remote transaction) going to be involved here?Jonathan Dickinson

1 Answers

2
votes

Are you looking for Task.WaitAll?

If a task actually times out - i.e. faults - then an AggregateException will be thrown. Note that WaitAll will wait for all the tasks to finish in one way or other before returning, even if some tasks fail early.

I have no reason to believe that TPL has any problem with tasks which take a very long time.