I think using posts will be the easiest way. If you use C # 4, it is very simple thanks to BlockingCollection <>
So you have a generic BlockingCollection, where Message is your message class.
Then in the workflow you do this
var msgEnum = blockingCollection.GetConsumingEnumerable(); //Per thread foreach( Message message in msgEnum ) { //Process messages here }
That's all.
The GetConsumingEnumerable () function will block until the message is processed. Then it will remove the message from the queue and your loop will process it.
What is nice about this is that you can add more threads, and each of them has only a foreach loop.
When you're done, call blockingCollection.CompletedAdding ();
The BTW queue processes concurrency and will send messages to the queue simultaneously, etc.
Hope this helps
Andre
source share