Редагувати

Поділитися через


BlockingCollection<T>.Add Method

Definition

Adds the item to the BlockingCollection<T>.

Overloads

Add(T)

Adds the item to the BlockingCollection<T>.

Add(T, CancellationToken)

Adds the item to the BlockingCollection<T>.

Add(T)

Source:
BlockingCollection.cs
Source:
BlockingCollection.cs
Source:
BlockingCollection.cs

Adds the item to the BlockingCollection<T>.

public:
 void Add(T item);
public void Add (T item);
member this.Add : 'T -> unit
Public Sub Add (item As T)

Parameters

item
T

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

Exceptions

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

-or-

The underlying collection didn't accept the item.

Remarks

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.

See also

Applies to

Add(T, CancellationToken)

Source:
BlockingCollection.cs
Source:
BlockingCollection.cs
Source:
BlockingCollection.cs

Adds the item to the BlockingCollection<T>.

public:
 void Add(T item, System::Threading::CancellationToken cancellationToken);
public void Add (T item, System.Threading.CancellationToken cancellationToken);
member this.Add : 'T * System.Threading.CancellationToken -> unit
Public Sub Add (item As T, cancellationToken As CancellationToken)

Parameters

item
T

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

cancellationToken
CancellationToken

A cancellation token to observe.

Exceptions

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.

-or-

The underlying collection didn't accept the item.

Remarks

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.

See also

Applies to