开发者

will completeAdding to wake up the thread already blocked by take

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜