Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Add Method (T, CancellationToken)
Collapse the table of content
Expand the table of content

BlockingCollection<T>.Add Method (T, CancellationToken)

.NET Framework 4.6 and 4.5

Adds the item to the BlockingCollection<T>.

Namespace:  System.Collections.Concurrent
Assemblies:   System.Collections.Concurrent (in System.Collections.Concurrent.dll)
  System (in System.dll)

public void Add(
	T item,
	CancellationToken cancellationToken
)

Parameters

item
Type: T

The item to be added to the collection. The value can be a null reference.

cancellationToken
Type: System.Threading.CancellationToken

A cancellation token to observe.

ExceptionCondition
OperationCanceledException

If the CancellationToken is canceled.

ObjectDisposedException

The BlockingCollection<T> has been disposed or the CancellationTokenSource that owns cancellationToken has been disposed.

InvalidOperationException

The BlockingCollection<T> has been marked as complete with regards to additions.

-or-

The underlying collection didn't accept the item.

If a bounded capacity was specified when this instance of BlockingCollection<T> was initialized, a call to Add may block until space is available to store the provided item.

This method can return early with an OperationCanceledException if the cancellationToken is canceled.

.NET Framework

Supported in: 4.6, 4.5, 4

.NET Framework Client Profile

Supported in: 4

.NET for Windows Phone apps

Supported in: Windows Phone 8.1

Portable Class Library

Supported in: Portable Class Library
Show:
© 2015 Microsoft