This documentation is archived and is not being maintained.

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

Adds the item to the BlockingCollection<T>.

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

public void Add(
	T item,
	CancellationToken cancellationToken


Type: T
The item to be added to the collection. The value can be a null reference.
Type: System.Threading.CancellationToken
A cancellation token to observe.


If the CancellationToken is canceled.


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


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


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

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.