简体   繁体   English

Java的ThreadPoolExecutor等效于C#?

[英]Java's ThreadPoolExecutor equivalent for C#?

I used to make good use of Java's ThreadPoolExecutor class and have yet to find a good equivalent in C#. 我曾经很好地利用了Java的ThreadPoolExecutor类,并且还没有在C#中找到一个好的等价物。 I know of ThreadPool.QueueUserWorkItem which is useful in many cases but no good if you want to control the number of threads assigned to a task or have multiple individual queues for different task types. 我知道ThreadPool.QueueUserWorkItem在许多情况下很有用,但如果你想控制分配给任务的线程数或者为不同的任务类型有多个单独的队列,那就没有用。

For example I liked to use a ThreadPoolExecutor with a single thread to guarantee sequential execution of asynchronous calls.. Is there an easy way to do this in C#? 例如,我喜欢使用带有单个线程的ThreadPoolExecutor来保证异步调用的顺序执行。在C#中有一种简单的方法吗? Is there a non-static thread pool implementation? 是否存在非静态线程池实现?

Until .Net 4.0 and the TPL, there is no such feature built-in. 直到.Net 4.0和TPL,内置没有这样的功能。

However, see this artcle 但是,请看这个artcle

As part of the Reactive Extensions (Rx), the Task Parallel Library was backported to .NET 3.5. 作为Reactive Extensions (Rx)的一部分,任务并行库被反向移植到.NET 3.5。 If you add a reference to the System.Threading.dll including in its distribution, you can use the TPL with .NET 3.5. 如果添加对System.Threading.dll的引用(包括其分发),则可以将TPL与.NET 3.5一起使用。

There are also thread pools built into the Concurrency and Coordination Runtime, which is freely available for use. 并发和协调运行时内置了一些线程池,可以免费使用。 See this MSDN article for use. 请参阅此MSDN文章以供使用。

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

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