Reputation: 1731
What would be difference between the following approach?
Task.Factory.StartNew(() => CustomConnection());
new Thread(CustomConnection).Start();
Both will create the new thread for performing the job. in what sense thread differs from task?
Performance wise which would the better option??
Upvotes: 2
Views: 522
Reputation: 14672
On key difference is that the Task approach will utilise the thread pool.
This is important as it means that you will only be creating as many threads as absolutely necessary. Where possible, existing threads will be re-used, giving the performance benefit of not having to create fresh threads.
If you are creating lots of threads, for relatively short running operations the above benefit becomes more important. If, however, the operation is one or just a few, long running operations, the benefit it less.
Upvotes: 4