Why so much difference in performance between Thread and Task?

The two are not the same.

When you use Task.Factory.StartNew, you’re scheduling a task to run on the ThreadPool. When you make a new Thread, you’re having to create and start a new thread.

In the first case, the threads are already created and reused. This causes the overhead of scheduling the tasks to be far lower, as the threads don’t have to be created each iteration.

Note that the behavior is not the same, however. When creating a separate thread, each task is getting it’s own thread. They will all get started right away. When using Task.Factory.StartNew, they’re put into the scheduler to run on the ThreadPool, which will (potentially) limit the number of concurrent threads started. This is usually a good thing, as it prevents overthreading from occurring.

Leave a Comment