I’m using a Producer-Consumer pattern and I use a BlockingCollection that produces data and consumes data from it. I call a method to produce the data and then set the BlockingCollection to CompleteAdding so that the consumer consumes all the data from the BlockingCollection. After some processing the application wants to add some other data to the BlockingCollection, but it can’t because it is set to CompleteAdding, how can I set CompleteAdding to false, or how can I consume all the data from the BlockingCollection, not waiting for the ComleteAdding?
I’m using a Producer-Consumer pattern and I use a BlockingCollection that produces data and
Share
You can’t – the whole point of calling
CompleteAddingis to say, “There will never be any more data added to this collection. Once it’s empty, you know you’re done.” What you’re asking for is a bit like saying, “After I’ve closed a network connection, how can I reopen it so I can write more data?”The fact that you want to suggests you should rethink your design. Perhaps you should be creating a new
BlockingCollectionat this point instead? Or perhaps you don’t really want to callCompleteAddingto start with?