Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between OnlyOnRanToCompletion and NotOnFaulted?

These two values are from the TaskContinuationOptions enumeration. I'm a bit unsure of which one to use.

Another pair I'm confused between is NotOnRanToCompletion and OnlyOnFaulted.

The wording is a bit confusing to me and each value from each pair seem to function equally. Am I missing something here?

like image 973
Ryan Peschel Avatar asked Oct 01 '11 20:10

Ryan Peschel


2 Answers

Yes: if something is canceled, it's neither faulted nor ran-to-completion; so it would be processed by NotOnRanToCompletion but not by OnlyOnFaulted.

So:

NotOnRanToCompletion | NotOnFaulted == OnlyOnCancelled
NotOnCanceled        | NotOnFaulted == OnlyOnRanToCompletion
NotOnRanToCompletion | NotOnCanceld == OnlyOnFaulted
like image 55
Jon Skeet Avatar answered Sep 18 '22 06:09

Jon Skeet


OnlyOnFaulted means that the continuation will run if the antecedent task throws an exception that is not handled by the task itself, unless the task was canceled.

NotOnRanToCompletion means that the continuation will not run if the task ran to completion, that is to say it will run if the task threw an exception, or if it was canceled.

So to summarize, if you want your continuation to run if the task is canceled or threw an exception, use NotOnRanToCompletion. If you want it to run only if it threw an exception but not if it is canceled, use OnlyOnFaulted.

like image 40
DeCaf Avatar answered Sep 19 '22 06:09

DeCaf