简体   繁体   中英

difference between new thread and task start new?

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??

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM