通用净生产者/消费者 [英] Generic .Net Producer/Consumer

查看:142
本文介绍了通用净生产者/消费者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我玩弄实现一个通用生产者/消费者对+处理队列在C#中的乐趣的想法。我们的想法是你可以创建实施适当IProducer和IConsumer接口(缺省实现提供的),这将主要包括委托对象,它们传递到 QueueProcessor ​​类的实例,告诉它有多少你想要的,走了。消费者

I'm toying with the idea of implementing a generic Producer/Consumer pair + processing queue in C# for fun. The idea is you can just create objects that implement appropriate IProducer and IConsumer interfaces (default implementations supplied), which will consist mainly of delegates, pass them to a QueueProcessor class instance, tell it how many consumers you want, and go.

不过,我对自己说,自我,当然这之前已经做了。

But I say to myself, "Self, surely this has been done before."

因此​​,没有人知道一个通用的实施在C#生产者/消费者模式(VB.Net是好的,太)?基本要求我在寻找:

So does anyone know of a good, generic implementation of the producer/consumer pattern in C# (VB.Net is okay, too)? The basic requirements I'm looking for:

  • 使用泛型的生产和消费的类型(输入,排队任务,和输出类型,或它们的任何组合)
  • 允许你指定多少消费者会工作队列
  • 允许你连接起来,或链条多个队列为管道(棘手多的消费者,我知道)
  • 允许你实现自己的生产者和消费者
  • 允许你把任何的IEnumerable到生产者(好吧,如果我要实现我自己,只要有可能)
  • 代表基(可以使用lambda语法的基本消费者或生产者的工作来处理一个单一的项目)

或者,如果没有,有什么陷阱都prevented它,你有没有对如何落实它的任何想法?

Or if there is none, what pitfalls have prevented it and do you have any thoughts on how to implement it?

推荐答案

微软CCR 包含许多你所需要的。

Microsoft CCR contains much of what you need.

此处一些code样品和使用说明。

Here are some code samples and usage notes.

这篇关于通用净生产者/消费者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆