Task.Factory.StartNew VS新任务 [英] Task.Factory.StartNew vs new Task

查看:123
本文介绍了Task.Factory.StartNew VS新任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道是否有做任何区别 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.StartNewreturns 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.StartNewand 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆