Task.Run和Task.Factory.Start的差异在创建线程方面是新的。 [英] Difference of Task.Run and Task.Factory.Start new in terms of creating threads.

查看:400
本文介绍了Task.Run和Task.Factory.Start的差异在创建线程方面是新的。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天,


我想问一下Task.Factory.StartNew和Task.Run之间的区别,我已经阅读了一些论坛和讨论其中提供相同的功能,但Task.Run旨在根据我阅读和理解的简单案例使用。
与ThreadPool相关的2之间是否存在任何差异,因为这两个任务和任务是管理线程池以及线程的创建?有点困惑,不知道哪种情况最好使用这两种情况。我做b $ b希望有关这些2的更容易理解的反馈,因为我开始在线程中使用这些。


非常感谢你们反馈。 :)

解决方案

在.NET Framework 4.5中引入了Task.Run方法,作为使用Task.Factory.StartNew的快捷方式无需指定一堆参数。 Task.Run是根据与Task.Factory.StartNew相同的逻辑实现的,只需传入
的一些默认参数。


请参阅Stephen的以下博客文章来自Microsoft PFX团队的Toub获取更多信息:
http:// blogs.msdn.com/b/pfxteam/archive/2011/10/24/10229468.aspx


Good Day,

I'd just like to ask the difference between Task.Factory.StartNew and Task.Run, I've read some forums and discussions that both of which offers the same functionality but Task.Run is meant to be use on simple cases according to what I've read and understood. Is there any differences between the 2 in relation to ThreadPool since these two are tasks and tasks are manage threadpools and also on the creation of threads? Kinda confused right and don't know which situation(s) would be the best to use these two. I do hope for a much easier-to-understand feedback regarding these 2 since i'm kinda starting up with the use of these in threading.

Thank you very much for the feedbacks. :)

解决方案

The Task.Run method was introduced in the .NET Framework 4.5 as a quick way to use Task.Factory.StartNew without needing to specify a bunch of parameters. Task.Run is implemented in terms of the same logic used for Task.Factory.StartNew, just passing in some default parameters.

Please refer to the following blog post by Stephen Toub from the Microsoft PFX team for more information: http://blogs.msdn.com/b/pfxteam/archive/2011/10/24/10229468.aspx


这篇关于Task.Run和Task.Factory.Start的差异在创建线程方面是新的。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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