views:

272

answers:

3

Hi,

I am trying to implement a queue thread that listen to some messages . What is the fastest way to do it , this is one-process mulitple thread application. Should I use Apache Qpid ? or just a regular .NET Blocking Queue Class (as in http://www.eggheadcafe.com/articles/20060414.asp)? I will be happy to hear your experience on this matter.

Yossef.

+1  A: 

Check out John Skeet's Producer Consumer example

SwDevMan81
+1  A: 

Do you need the queue to be persistent? In other words, if the process dies for some reason, do you still need to be able to continue? If so, that complicates things significantly. If not, I'd go with a regular blocking queue - if you're able to use .NET 4.0, go for the new concurrent collections. which make all this very easy.

Note that the sample given in my article which SwDevMan81 referenced is quite a simple one, and it pre-dates generics. For a more production-quality implementation you'd want a good way of stopping the queue, generics, exception handling etc. My implementation is a reasonable starting point, but it shouldn't be seen as the final product.

Jon Skeet
Thanks. No need to the queue to be persistent.
yosefb
A: 

I'd avoid any code that uses Thread.Sleep(). Until .NET 4.0 becomes widely available, consider using Joe Duffy's BlockingQueue class.

Hans Passant
Why should I consider to avoid Thread.Sleep() until .net 4.0 is out?
yosefb
You asked for "fastest". A thread that sleeps for a hundred milliseconds can never be fast.
Hans Passant
ok, but why avoid Thread.Sleep() until .net 4.0? whats so special about .net 4.0 that I will be able to use thread.sleep() in .net 4?
yosefb
Not what I meant. .NET 4.0 will have the ConcurrentQueue class built-in. You want to avoid code that uses Thread.Sleep() because that's code that's not doing anything useful while it is sleeping. It is slow code.
Hans Passant