Creating threads - Task.Factory.StartNew vs new Thread()

前端 未结 4 1487
感动是毒
感动是毒 2020-11-29 16:48

I am just learning about the new Threading and Parallel libraries in .Net 4

In the past I would create a new Thread like so (as an example):

DataInTh         


        
4条回答
  •  长情又很酷
    2020-11-29 17:07

    There is a big difference. Tasks are scheduled on the ThreadPool and could even be executed synchronous if appropiate.

    If you have a long running background work you should specify this by using the correct Task Option.

    You should prefer Task Parallel Library over explicit thread handling, as it is more optimized. Also you have more features like Continuation.

提交回复
热议问题