BlockingCollection<T>.TryAdd メソッド
定義
BlockingCollection<T> に対して、指定した項目の追加を試みます。Tries to add the specified item to the BlockingCollection<T>.
オーバーロード
TryAdd(T, Int32) |
指定した期間内に、BlockingCollection<T> に対して指定した項目の追加を試みます。Tries to add the specified item to the BlockingCollection<T> within the specified time period. |
TryAdd(T, Int32, CancellationToken) |
キャンセル トークンを観察しながら、指定した期間内に、BlockingCollection<T> に対して指定した項目の追加を試みます。Tries to add the specified item to the BlockingCollection<T> within the specified time period, while observing a cancellation token. |
TryAdd(T) |
BlockingCollection<T> に対して、指定した項目の追加を試みます。Tries to add the specified item to the BlockingCollection<T>. |
TryAdd(T, TimeSpan) |
BlockingCollection<T> に対して、指定した項目の追加を試みます。Tries to add the specified item to the BlockingCollection<T>. |
TryAdd(T, Int32)
指定した期間内に、BlockingCollection<T> に対して指定した項目の追加を試みます。Tries to add the specified item to the BlockingCollection<T> within the specified time period.
public:
bool TryAdd(T item, int millisecondsTimeout);
public bool TryAdd (T item, int millisecondsTimeout);
member this.TryAdd : 'T * int -> bool
Public Function TryAdd (item As T, millisecondsTimeout As Integer) As Boolean
パラメーター
- item
- T
コレクションに追加する項目。The item to be added to the collection.
- millisecondsTimeout
- Int32
待機するミリ秒数。無制限に待機する場合は Infinite (-1)。The number of milliseconds to wait, or Infinite (-1) to wait indefinitely.
戻り値
指定した時間内にコレクションに item
を追加できた場合は true
。それ以外の場合は false。true
if the item
could be added to the collection within the specified time; otherwise, false. 項目が重複しており、基になるコレクションが項目の重複を受け入れない場合は、InvalidOperationException がスローされます。If the item is a duplicate, and the underlying collection does not accept duplicate items, then an InvalidOperationException is thrown.
例外
BlockingCollection<T> は破棄されています。The BlockingCollection<T> has been disposed.
millisecondsTimeout
は無限のタイムアウトを表す -1 以外の負の数です。millisecondsTimeout
is a negative number other than -1, which represents an infinite time-out.
BlockingCollection<T> は、追加に関して完了としてマークされました。The BlockingCollection<T> has been marked as complete with regards to additions.
- または --or- 基になるコレクションが項目を受け入れませんでした。The underlying collection didn't accept the item.
適用対象
TryAdd(T, Int32, CancellationToken)
キャンセル トークンを観察しながら、指定した期間内に、BlockingCollection<T> に対して指定した項目の追加を試みます。Tries to add the specified item to the BlockingCollection<T> within the specified time period, while observing a cancellation token.
public:
bool TryAdd(T item, int millisecondsTimeout, System::Threading::CancellationToken cancellationToken);
public bool TryAdd (T item, int millisecondsTimeout, System.Threading.CancellationToken cancellationToken);
member this.TryAdd : 'T * int * System.Threading.CancellationToken -> bool
Public Function TryAdd (item As T, millisecondsTimeout As Integer, cancellationToken As CancellationToken) As Boolean
パラメーター
- item
- T
コレクションに追加する項目。The item to be added to the collection.
- millisecondsTimeout
- Int32
待機するミリ秒数。無制限に待機する場合は Infinite (-1)。The number of milliseconds to wait, or Infinite (-1) to wait indefinitely.
- cancellationToken
- CancellationToken
観察するキャンセル トークン。A cancellation token to observe.
戻り値
指定した時間内にコレクションに item
を追加できた場合は true
。それ以外の場合は false。true
if the item
could be added to the collection within the specified time; otherwise, false. 項目が重複しており、基になるコレクションが項目の重複を受け入れない場合は、InvalidOperationException がスローされます。If the item is a duplicate, and the underlying collection does not accept duplicate items, then an InvalidOperationException is thrown.
例外
CancellationToken が取り消されている場合。If the CancellationToken is canceled.
BlockingCollection<T> が破棄されているか、または基になっている CancellationTokenSource が破棄されています。The BlockingCollection<T> has been disposed or the underlying CancellationTokenSource has been disposed.
millisecondsTimeout
は無限のタイムアウトを表す -1 以外の負の数です。millisecondsTimeout
is a negative number other than -1, which represents an infinite time-out.
BlockingCollection<T> は、追加に関して完了としてマークされました。The BlockingCollection<T> has been marked as complete with regards to additions.
- または --or- 基になるコレクションが項目を受け入れませんでした。The underlying collection didn't accept the item.
適用対象
TryAdd(T)
BlockingCollection<T> に対して、指定した項目の追加を試みます。Tries to add the specified item to the BlockingCollection<T>.
public:
bool TryAdd(T item);
public bool TryAdd (T item);
member this.TryAdd : 'T -> bool
Public Function TryAdd (item As T) As Boolean
パラメーター
- item
- T
コレクションに追加する項目。The item to be added to the collection.
戻り値
item
を追加できる場合は true
。それ以外の場合は false
。true
if item
could be added; otherwise, false
. 項目が重複しており、基になるコレクションが項目の重複を受け入れない場合は、InvalidOperationException がスローされます。If the item is a duplicate, and the underlying collection does not accept duplicate items, then an InvalidOperationException is thrown.
例外
BlockingCollection<T> は破棄されています。The BlockingCollection<T> has been disposed.
BlockingCollection<T> は、追加に関して完了としてマークされました。The BlockingCollection<T> has been marked as complete with regards to additions.
- または --or- 基になるコレクションが項目を受け入れませんでした。The underlying collection didn't accept the item.
注釈
コレクションが制限付きコレクションであり、いっぱいの場合、このメソッドは項目を追加せずに、直ちに false を返します。If the collection is a bounded collection, and is full, this method immediately returns false without adding the item.
適用対象
TryAdd(T, TimeSpan)
BlockingCollection<T> に対して、指定した項目の追加を試みます。Tries to add the specified item to the BlockingCollection<T>.
public:
bool TryAdd(T item, TimeSpan timeout);
public bool TryAdd (T item, TimeSpan timeout);
member this.TryAdd : 'T * TimeSpan -> bool
Public Function TryAdd (item As T, timeout As TimeSpan) As Boolean
パラメーター
- item
- T
コレクションに追加する項目。The item to be added to the collection.
- timeout
- TimeSpan
待機するミリ秒数を表す TimeSpan。無制限に待機する場合は、-1 ミリ秒を表す TimeSpan。A TimeSpan that represents the number of milliseconds to wait, or a TimeSpan that represents -1 milliseconds to wait indefinitely.
戻り値
指定した期間内にコレクションに item
を追加できた場合は true
。それ以外の場合は false
。true
if the item
could be added to the collection within the specified time span; otherwise, false
.
例外
BlockingCollection<T> は破棄されています。The BlockingCollection<T> has been disposed.
timeout
が -1 ミリ秒以外の負数です。-1 は無制限のタイムアウトを表します。または、タイムアウトが MaxValue を超えています。timeout
is a negative number other than -1 milliseconds, which represents an infinite time-out -or- timeout is greater than MaxValue.
BlockingCollection<T> は、追加に関して完了としてマークされました。The BlockingCollection<T> has been marked as complete with regards to additions.
- または --or- 基になるコレクションが項目を受け入れませんでした。The underlying collection didn't accept the item.