每个任务都有单独的线程池
我的应用程序有两个主要任务:编码、处理视频。 这些任务是独立的。 我希望使用可配置数量的线程来运行每个任务。 因此,对于一项任务,我通常使用 ThreadPool 和 SetMaxThreads。但现在我有两个任务,并且希望“每个任务有两个可配置(线程数)线程池”。 嗯,ThreadPool 是一个静态类。那么我如何实现我的策略(每个任务的线程数易于配置)。
谢谢
I've got application which has two main task: encoding, processing video.
These tasks are independant.
Each task I would like run with configurable number of threads.
For this reason for one task I usually use ThreadPool and SetMaxThreads. But now I've got two tasks and would like "two configurable(number of threads) threapool for each task".
Well, ThreadPool is a static class. So how can I implement my strategy(easy configurable number of threads for each task).
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能需要自己的线程池。如果您使用 .NET 4.0,那么使用
BlockingCollection
类实际上很容易推出您自己的产品。这就是它的全部内容。您可以为您想要控制的每个实际池创建一个
CustomThreadPool
。我发布了最少量的代码来让一个粗略的线程池运行。当然,您可能想要调整和扩展此实现以满足您的特定需求。You will probably want your own thread pool. If you are using .NET 4.0 then it is actually fairly easy to roll your own if you use the
BlockingCollection
class.That is really all there is to it. You would create a
CustomThreadPool
for each actual pool you want to control. I posted the minimum amount of code to get a crude thread pool going. Naturally, you might want to tweak and expand this implementation to suit your specific need.