Why doesn't TPL support support multitasking sequels?

TPL has several TaskContinuationOptions values ​​that determine the circumstances in which the task runs. For example, TaskContinuationOptions.NotOnCanceled prevents the task from starting when the parent element is disabled.

However, none of these task state filters apply to the continuation of several tasks. You cannot do something like:

 TaskFactory f = new TaskFactory(); Task t1 = new Task (() => Thread.Sleep (5000)); Task t2 = new Task (() => Thread.Sleep (4000)); Task t3 = f.ContinueWhenAll (new Task[] { t1, t2 }, (tasks) => { ... }, TaskContinuationOptions.OnlyOnRanToCompletion); 

As a result, you get the error message "It is invalid to exclude specific continuation kinds for continuations off of multiple tasks."

I do not understand why this condition will be excluded from the API. Why not be a perfectly acceptable use case, so that the task is performed only when all the antecedents have ended in a certain state?

+7
source share
2 answers

"... to run only when all the antecedents have ended in a certain state ..."

Pay attention to your word “everything”, I’m not MS, but I bet that this is due to the need for another full TaskContinuationOptions enum, which included All , Any , OnlyOne , AllButOne , etc. etc.

In addition, Eric Lippert always answers the following questions: “It's expensive and takes a lot of time to add a“ simple ”function. Equation than using the basics correctly and giving users the opportunity to implement the rest.

0
source

ContinueWhenAll means "start continuation when all tasks completed successfully." Specifying NotOn* or OnlyOn* will either be the opposite or redundant for this definition. See the Notes section of this MSDN article .

0
source

All Articles