Possible Duplicate:
Creating a blocking Queue<T> in .NET?
I have typical producer and consumer threading issue. However the only difference is that the producer is allowed to build up a buffer of 5 items after which it has to wait until some items are consumed.
What would be the best solutions to implement this in c#. Currently I have it implemented using a semaphore however the producer seems to build up a buffer of over 100 items very rapidly. I have no syntax to handle limiting the buffer to 5 items. I was thinking of using a static integer - have the producer increment it - when it reaches 5 the producer goes to sleep. Have the consumer decrement it and wake up the producer.