Add to BlockingCollection after completion of add

I use the Producer-Consumer problem and have a BlockingCollection that I get data from and consume the date from it. I call the method for creating data and set the blockingcollection to CompleteAdding so that the consumer consumes all the data from BC (blockingcollection), and after some processing the application wants to add some other data to BC, but cannot because it is set to CompleteAdding, how can I set CompleteAdding to false or how can I use all the data from BC without waiting for ComleteAdding?

Thanks.

+6
source share
1 answer

You can't - the whole point of calling CompleteAdding is to say: "No data will be added to this collection anymore. Once it is empty, you know you're done." What you are asking for is a bit like saying: "After I closed the network connection, how can I open it so that I can write more data?"

The fact that you want to offer should redefine your design. Perhaps you should create a new BlockingCollection instead? Or maybe you really don't want to call CompleteAdding to start with?

+10
source

Source: https://habr.com/ru/post/924162/


All Articles