Blocking BufferBlock?
-
Monday, January 14, 2013 9:28 AM
We've tried BufferBlock with rather small bound capacity and discovered, that when the buffer fills up - new messages disappear. We'd like to use something like BufferBlock + BlockingCollection hybrid (BlockingBufferBlock), so in case buffer is full - all the producers are suspended for a while. Is it anything out there?
P.S.We use version from DevLab (.net 4.0 & VS2010)
Sergejus Barinovas
- Edited by SergejusMVP Monday, January 14, 2013 9:30 AM
- Edited by SergejusMVP Monday, January 14, 2013 11:12 AM
All Replies
-
Monday, January 14, 2013 2:25 PM
That depends on how you post items to the block.
If you use Post() and the target block is full, the method will return false. If you don't check the return value, it may appear as if the messages disappeared.
If you use SendAsync(), then the returned Task will complete only after the message has been accepted or declined. You can use this Task to await (or Wait() if you really want to block) until the message has been accepted. The value of the Task indicates whether the message was accepted or declined. In the case of BufferBlock, a message from SendAsync() can be declined only if the block has been Complete()d.
- Edited by svick Monday, January 14, 2013 2:25 PM
- Edited by svick Monday, January 14, 2013 2:26 PM
- Marked As Answer by SergejusMVP Monday, January 14, 2013 2:43 PM

