Java ThreadPoolExecutor equivalent for C #?

I used to use the Java class ThreadPoolExecutor and have not yet found a good equivalent in C #. I know ThreadPool.QueueUserWorkItem, which is useful in many cases, but not suitable if you want to control the number of threads assigned to a task, or have several separate queues for different types of tasks.

For example, I liked using a ThreadPoolExecutor with a single thread to ensure that asynchronous calls are made sequentially. Is there an easy way to do this in C #? Is there a non-stationary implementation of a thread pool?

+4
source share
2 answers

Prior to .Net 4.0 and TPL, there is no such built-in function.

However, see this artcle

+2
source

As part of Reactive Extensions (Rx), a parallel task library has been transferred back to .NET 3.5. If you add a link to the System.Threading.dll file, including its distribution, you can use TPL with .NET 3.5.

There are also stream pools built into Concurrency and reconciliation time that are freely available for use. See the MSDN article for use.

0
source

Source: https://habr.com/ru/post/1308672/


All Articles