other/Scripts/Network/RPCNet/Base/AsyncCollection.cs
/// <summary>
/// Attempts to remove an item from the AsyncCollection.
/// A <see cref="System.OperationCanceledException"/> is thrown if the <see cref="CancellationToken"/> is
/// canceled.
/// </summary>
/// <param name="result">The item removed from the collection.</param>
/// <param name="millisecondsTimeout">The number of milliseconds to wait, or <see
/// cref="System.Threading.Timeout.Infinite"/> (-1) to wait indefinitely.</param>
/// <param name="cancellationToken">A cancellation token to observe.</param>
/// <returns>true if an item could be removed from the collection within
/// the alloted time; otherwise, false.</returns>
/// <exception cref="OperationCanceledException">If the <see cref="CancellationToken"/> is canceled.</exception>
/// <exception cref="T:System.ObjectDisposedException">The AsyncCollection has been disposed.</exception>
/// <exception cref="T:System.ArgumentOutOfRangeException"><paramref name="millisecondsTimeout"/> is a
/// negative number other than -1, which represents an infinite time-out.</exception>
Attempts to remove an item from the AsyncCollection.
A  is thrown if the  is
canceled.
Attempts to remove an item from the AsyncCollection . A is thrown if the is canceled .
public bool TryTake(out T result, int millisecondsTimeout, CancellationToken cancellationToken = new CancellationToken())
        {
            CheckDisposed();
            CancellationTokenSource linked =
                CancellationTokenSource.CreateLinkedTokenSource(doneCancellationToken.Token, cancellationToken);
            try
            {
                if (IsCompleted)
                {
                    result = default(T);
                    return false;
                }
                if (semaphore.Wait(0))
                {
                    if (queue.TryDequeue(out result))
                        return true;
                    throw new InvalidOperationException();
                }
                try
                {
                    if (semaphore.Wait(millisecondsTimeout, linked.Token))
                    {
                        if (queue.TryDequeue(out result))
                            return true;
                        throw new InvalidOperationException();
                    }
                    else
                    {
                        result = default(T);
                        return false;
                    }
                }
                catch (OperationCanceledException)
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    result = default(T);
                    return false;
                }
            }
            finally
            {
                linked.Dispose();
            }
        }
public bool TryTake ( out T result , int millisecondsTimeout , CancellationToken cancellationToken = new CancellationToken ( ) ) { CheckDisposed ( ) ; CancellationTokenSource linked = CancellationTokenSource . CreateLinkedTokenSource ( doneCancellationToken . Token , cancellationToken ) ; try { if ( IsCompleted ) { result = default ( T ) ; return false ; } if ( semaphore . Wait ( 0 ) ) { if ( queue . TryDequeue ( out result ) ) return true ; throw new InvalidOperationException ( ) ; } try { if ( semaphore . Wait ( millisecondsTimeout , linked . Token ) ) { if ( queue . TryDequeue ( out result ) ) return true ; throw new InvalidOperationException ( ) ; } else { result = default ( T ) ; return false ; } } catch ( OperationCanceledException ) { cancellationToken . ThrowIfCancellationRequested ( ) ; result = default ( T ) ; return false ; } } finally { linked . Dispose ( ) ; } }
Attempts to remove an item from the AsyncCollection.
Attempts to remove an item from the AsyncCollection .
true if an item could be removed from the collection within
the alloted time; otherwise, false.
true if an item could be removed from the collection within the alloted time ; otherwise false .
If the  is canceled.
If the is canceled .
The AsyncCollection has been disposed.
The AsyncCollection has been disposed .
None
T
out
millisecondsTimeout
int
The number of milliseconds to wait, or  (-1) to wait indefinitely.
The number of milliseconds to wait or ( - 1 ) to wait indefinitely .
cancellationToken
CancellationToken
A cancellation token to observe.
A cancellation token to observe .
result
The item removed from the collection.
The item removed from the collection .