in the case that the consumer is already blocked by take()开发者_如何学Python , will producer's completeAdding wake it up? using BlockingCollection. MSDN does not state it clearly.
No.
A quick experiment shows it will throw an InvalidOperation exception in the Take() method.
And that makes sense:
int value = data.Take();
What would value
be when the Thread/Task would just 'wake up' without any data to return ?
If you are blocked with TryTake(out x)
it will return with false
when Adding is completed.
I'm not very familiar with BlockingCollections, but in general my understanding is that if something is blocked it does not get "woken up" by a third party.
精彩评论