System.Collections.Concurrent.BlockingCollection<T>.GetConsumingEnumerable Method

Provides a consuming IEnumerable`1 for items in the collection.

Syntax

public IEnumerable<T> GetConsumingEnumerable (System.Threading.CancellationToken cancellationToken)

Parameters

cancellationToken
A cancellation token to observe.

Returns

An IEnumerable`1 that removes and returns items from the collection.

Remarks

This method enables client code to remove items from the collection by using a foreach loop (For Each in Visual Basic), or System.Threading.Tasks.Parallel.ForEach``1(Partitioner<``0>, Action<``0>) or a PLINQ query. The enumerator will continue to provide items (if any exist) until BlockingCollection`1.IsCompleted returns true, and if BlockingCollection`1.IsCompleted is false the loop blocks until an item becomes available or until the System.Threading.CancellationToken is cancelled.

Requirements

Namespace: System.Collections.Concurrent
Assembly: System (in System.dll)
Assembly Versions: 4.0.0.0