質問

The MSDN remarks at http://msdn.microsoft.com/en-us/library/dd267312.aspx state that...

"The default collection type for BlockingCollection is ConcurrentQueue"

Does this mean that while I am running "GetConsumingEnumerable()" on the collection, the item pulled is being dequeued from the queue and after use will be marked for GC?

In other words... In the following snippet,

foreach (var item in collection.GetConsumingEnumerable())
        {
            //do something with item
        }

what happens to item after the loop iteration?

役に立ちましたか?

解決

The items will be removed from the collection, and if no other references to them exist they will be eligible for collection.

From the documentation of GetConsumingEnumerable:

Return Value
Type: System.Collections.Generic.IEnumerable<T>
An IEnumerable<T> that removes and returns items from the collection.

(my emphasis)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top