We’re using Parallel.foreach to consume items from a blocking collection. I know that by default partioning happens when this is done. I’d like to understand more how this may affect locks/blocking on a BlockingCollection. Is there any cases where an add operation on the blocking collection could be blocked when threads are consuming?
thanks
It could (see How to: Add and Take Items Individually from a BlockingCollection)
So it will block on adding if the collection is at maximum capacity.
If you consume the items in a foreach loop, adding items will not block during this, but there are a couple of things you will need to note: