What values use ContinueWith(Action<Task> continuationAction)
for CancellationToken
, TaskContinuationOptions
and TaskScheduler
and where can I find this in the official documentation?
The ContinueWith function is a method available on the task that allows executing code after the task has finished execution. In simple words it allows continuation. Things to note here is that ContinueWith also returns one Task. That means you can attach ContinueWith one task returned by this method.
ContinueWith(Action<Task,Object>, Object, TaskScheduler) Creates a continuation that receives caller-supplied state information and executes asynchronously when the target Task completes. The continuation uses a specified scheduler.
MSDN does not explicitly state this but usually when you have method overloads, all other parameters are "default". Let's find this method in .NET source:
public Task ContinueWith(Action<Task, Object> continuationAction)
{
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
return ContinueWith(continuationAction, TaskScheduler.Current, default(CancellationToken), TaskContinuationOptions.None, ref stackMark);
}
So default CancellationToken
(that is CancellationToken.None
), empty TaskContinuationOptions
and current TaskScheduler
are used.
You can look at most of the actual source code for .Net on http://referencesource.microsoft.com/. In your case the exact overload (ContinueWith(Action<Task> continuationAction)
) looks like this:
public Task ContinueWith(Action<Task> continuationAction)
{
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
return ContinueWith(continuationAction, TaskScheduler.Current, default(CancellationToken), TaskContinuationOptions.None, ref stackMark);
}
So, for CancellationToken
it's default(CancellationToken)
which is equivalent to CancellationToken.None
.
For TaskContinuationOptions
it's TaskContinuationOptions.None
.
For TaskScheduler
it's TaskScheduler.Current
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