We are using this code snippet from StackOverflow to produce a Task that completes as soon as the first of a collection of tasks completes successfully. Due to the non-linear na
If current task is a child task, then using TaskScheduler.Current
will mean the scheduler will be that which the task it is in, is scheduled to; and if not inside another task, TaskScheduler.Current
will be TaskScheduler.Default
and thus use the ThreadPool.
If you use TaskScheduler.Default
, then it will always go to the ThreadPool.
The only reason you would use TaskScheduler.Current
:
To avoid the default scheduler issue, you should always pass an explicit
TaskScheduler
toTask.ContinueWith
andTask.Factory.StartNew
.
From Stephen Cleary's post ContinueWith is Dangerous, Too.
There's further explanation here from Stephen Toub on his MSDN blog.