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?
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
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With