According to Microsoft (link), there are two ways to start a task: Implicit and Explicit.
Assume that I created 4 different tasks in main thread called task1, task2, task3 and task4.
case1: I run them all, explicitly in main thread:
task1.Start();
task2.Start();
task3.Start();
task4.Start();
case2: I run them implicitly using Parallel.Invoke method in main thread:
Parallel.Invoke(task1, task2, task3, task4);
The only difference I noticed is that in case2, the main thread suspends until Invoke( ) returns.
My question is about the Task scheduler.
Does the task scheduler behave 4 tasks in case1 and case2 differently in terms of scheduling or they are completely equivalent ?
in the same link I have mentioned above we read:
Behind the scenes, tasks are queued to the ThreadPool, which has been
enhanced with algorithms (like hill-climbing) that determine and
adjust to the number of threads that maximizes throughput. This makes
tasks relatively lightweight, and you can create many of them to
enable fine-grained parallelism. To complement this, widely-known
work-stealing algorithms are employed to provide load-balancing.
This blog post from the Parallel team should answer some of your questions.
Short answer: with Tasks you will have to do a Task::WaitAll(…) on your main thread to prevent from exiting where as Parallel::Invoke will actually take care of this for you. Beyond that, nothing else because the same TPL infrastructure is used under Parallel::Invoke.