简体   繁体   English

在.NET 4中,BeginInvoke和Task是否使用相同的线程池?

[英]In .NET 4, does BeginInvoke and Task use the same threadpool?

.NET 4 introduced a brand new thread pool design accessed by the Task Parallel library. .NET 4引入了由Task Parallel库访问的全新线程池设计。 But if I have old code that uses Delegate.BeginInvoke, will those be executed by that new thread pool? 但是,如果我有使用Delegate.BeginInvoke的旧代码,那些新线程池会执行吗? Or is the old thread pool still in the runtime somewhere? 或旧的线程池仍然在运行时的某个地方?

They both use the same ThreadPool. 它们都使用相同的ThreadPool。 ThreadPool.QueueUserWorkItem does, as well. ThreadPool.QueueUserWorkItem也可以。

However, Delegate.BeginInvoke has extra overhead when compared to Task.Factory.StartNew, and does not take advantages of many of the features in the ThreadPool, such as work stealing or the new debugging features. 但是,与Task.Factory.StartNew相比, Delegate.BeginInvoke有额外的开销,并且没有利用ThreadPool中的许多功能,例如工作窃取或新的调试功能。 I would recommend refactoring this to use the new Task features as time permits. 我建议重构这个以在时间允许的情况下使用新的Task功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM