c# - Observing changes in a BlockingCollection without consuming -


a consumer thread , multiple producer threads synchronize work system.collections.concurrent.blockingcollection<t>.

the producers call blockingcollection.add()
, consumer runs
foreach (var item in blockingcollection.getconsumingenumerable()) {...}

now 1 producer wants "flush" buffer: producer wants wait until current items have been consumed. other producers may add further items in meantime, producer interested in items in queue.

how can make producer wait, without using busy waiting?

in essence i want non-consumer threads notified whenever item of blockingcollection consumed .

i can set autoresetevent in consumer, wake 1 thread waiting changes, when there multiple:

foreach (var item in blockingcollection.getconsumingenumerable())  {     myautoresetevent.set() } 

i can set manualresetevent:

foreach (var item in blockingcollection.getconsumingenumerable())  {     mymanualresetevent.set() } 

this wake waiting threads, how switch off again?

in case end using comment

put dummy item in collection wakes producer


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -