I'm trying to wrap my head around the TPL, the new async
/ await
features in C# 5, and the mysteries of TaskCompletionSource
.
One thing that isn't clear to me is when to use SetResult
, SetException
, and SetCancel
versus TrySetResult
, TrySetException
and TrySetCancel
.
This is what MSDN has to say:
This operation will return false if the Task is already in one of the three final states: RanToCompletion, Faulted, or Canceled.
This method also returns false if the underlying Task has already been disposed.
Ok, I get that, but it doesn't really offer any guidance on when or why to use one over the other.
So, what's the deal?