开发者

will completeAdding to wake up the thread already blocked by take

开发者 https://www.devze.com 2023-03-03 06:45 出处:网络
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.

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

精彩评论

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