开发者

Looking for a .NET 4 ThreadPool [closed]

开发者 https://www.devze.com 2023-02-22 10:33 出处:网络
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 8 years ago.

Improve this question

I am looking for a good ThreadPool implementation. I understand that the .NET ThreadPool has been rewritten/improved in .NET 4, but I doubt that it suits my needs.

I have a varying number of tasks that have to be executed in parallel. I want to be able to control the maximum number of threads that work on these tasks, and if possible be able to priorize the tasks. Idle threads should be disposed and new threads should be created when necessary, up to the specified minimum/maximum.

As I understand it, I can't control the number of threads the .NET ThreadPool uses to process my tasks (don't want to affect the rest of the application, i.e. delegates) and I can't assign a number of threads t开发者_如何学Goo only work on my tasks.

So my questions are:

  • Is there a way to use the .NET ThreadPool in my scenario?
  • If not, which good (preferably free) ThreadPool implementations are out there that I should look at? (.NET Framework 4 and Windows Azure compatible)

EDIT: Added varying number of threads as a requirement.


You should take a look at that library.

http://smartthreadpool.codeplex.com/


I think you're looking for the System.Threading.Tasks.Task class. Simplified, it's like using the ThreadPool but it gives you back Tasks, which have a similar API to Threads. Don't think you can prioritise Tasks though, but you did say you want to run stuff in parallel.


Beauty of the implementation of ThreadPool is its ability to react to load of the pool by increasing/decreasing its pool size.

If you do not have such requirement (a fixed number of threads work for you) then you might not need an elaborate thread pool. So all you might need a simple class abstracting creating and managing threads.


Maybe the Partitioner can help you out?

Further informations on how to use it can be found int the Patterns for Parallel Programming: Understanding and Applying Parallel Patterns with the .NET Framework 4.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号