Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the ContinueWith default values

What values use ContinueWith(Action<Task> continuationAction) for CancellationToken, TaskContinuationOptions and TaskScheduler and where can I find this in the official documentation?

like image 982
Jotrius Avatar asked Jun 11 '15 09:06

Jotrius


People also ask

What is ContinueWith in c#?

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.

How does ContinueWith work?

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.


2 Answers

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.

like image 111
andreycha Avatar answered Oct 08 '22 04:10

andreycha


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

like image 1
i3arnon Avatar answered Oct 08 '22 04:10

i3arnon