Task.Run is a shorthand for Task.Factory.StartNew with specific safe arguments:Task.Factory.StartNew( action, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);它是在 .Net 4.5 中添加的,以帮助越来越频繁地使用 async 并将工作卸载到 ThreadPool.It was added in .Net 4.5 to help with the increasingly frequent usage of async and offloading work to the ThreadPool.Task.Factory.StartNew(在 .Net 4.0 中添加了 TPL)更加健壮.你应该只在 Task.Run 不够用时才使用它,例如当你想使用 TaskCreationOptions.LongRunning 时(尽管当委托是异步的时候它是不必要的.更多关于在我的博客上:LongRunning 对 Task.Run 无用 async-等待).在 Task.Factory.StartNew>Task.Run 与 Task.Factory.StartNewTask.Factory.StartNew (added with TPL in .Net 4.0) is much more robust. You should only use it if Task.Run isn't enough, for example when you want to use TaskCreationOptions.LongRunning (though it's unnecessary when the delegate is async. More on that on my blog: LongRunning Is Useless For Task.Run With async-await). More on Task.Factory.StartNew in Task.Run vs Task.Factory.StartNew永远不要创建Task 并调用Start(),除非你找到了一个非常好的理由这样做.仅当您有一部分需要创建任务但不安排它们而另一部分需要安排而不创建时才应使用它.这几乎从来都不是一个合适的解决方案,而且可能很危险.Task.Factory.StartNew"与new"中的更多信息任务(...).开始"Don't ever create a Task and call Start() unless you find an extremely good reason to do so. It should only be used if you have some part that needs to create tasks but not schedule them and another part that schedules without creating. That's almost never an appropriate solution and could be dangerous. More in "Task.Factory.StartNew" vs "new Task(...).Start"总而言之,主要使用Task.Run,如果必须使用Task.Factory.StartNew,不要使用Start.In conclusion, mostly use Task.Run, use Task.Factory.StartNew if you must and never use Start. 这篇关于关于 Task.Start() , Task.Run() 和 Task.Factory.StartNew() 的使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-23 09:07