Task.Factory.StartNew VS新任务 [英] Task.Factory.StartNew vs new Task
问题描述
有谁知道是否有做任何区别 Task.Factory.StartNew
VS 新任务
随后致电开始
的任务。看着反射似乎没有成为太大的差别。因此,或许唯一不同的是 Task.Factory.StartNew
返回已启动的任务。这是正确的?
Does anyone know if there is any difference between doing Task.Factory.StartNew
vs new Task
followed by calling Start
on the task. Looking at reflector there doesn't seem to be much difference. So perhaps the only difference is that Task.Factory.StartNew
returns a task that is already started. Is this correct?
我知道 Task.Factory.StartNew
和 Task.Run
有不同的默认选项, Task.Run
是.NET 4.5的preferred选项。
I know that Task.Factory.StartNew
and Task.Run
have different default options and Task.Run
is the preferred option for .Net 4.5.
推荐答案
我发现的这个通过斯蒂芬Toub,这解释那其实是有性能损失使用新建任务(...)。启动()
,因为当大文章启动方法需要使用同步,以确保任务只调度一次。
I found this great article by Stephen Toub, which explains that there is actually a performance penalty when using new Task(...).Start()
, as the start method needs to use synchronization to make sure the task is only scheduled once.
他的建议是preFER使用 Task.Factory.StartNew
为.NET 4.0。对于.NET 4.5 Task.Run
是的更好的选择。
His advice is to prefer using Task.Factory.StartNew
for .net 4.0. For .net 4.5 Task.Run
is the better option.
这篇关于Task.Factory.StartNew VS新任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!