BlockingCollection<T>::GetConsumingEnumerable Method (CancellationToken)
Provides a consuming IEnumerable<T> for items in the collection.
Assembly: System (in System.dll)
Parameters
- cancellationToken
-
Type:
System.Threading::CancellationToken
A cancellation token to observe.
Return Value
Type: System.Collections.Generic::IEnumerable<T>^An IEnumerable<T> that removes and returns items from the collection.
| Exception | Condition |
|---|---|
| OperationCanceledException | If the CancellationToken is canceled. |
| ObjectDisposedException | The BlockingCollection<T> has been disposed or the CancellationTokenSource that created cancellationToken has been disposed |
This method enables client code to remove items from the collection by using a foreach loop (For Each in Visual Basic), or Parallel::ForEach<TSource> or a PLINQ query. The enumerator will continue to provide items (if any exist) until IsCompleted returns true, and if IsCompleted is false the loop blocks until an item becomes available or until the CancellationToken is cancelled.
Available since 8
.NET Framework
Available since 4.0
Portable Class Library
Supported in: portable .NET platforms
Windows Phone
Available since 8.1