Пример #1
0
        // Token: 0x06003DF7 RID: 15863 RVA: 0x000E6388 File Offset: 0x000E4588
        private async Task <bool> WaitUntilCountOrTimeoutAsync(SemaphoreSlim.TaskNode asyncWaiter, int millisecondsTimeout, CancellationToken cancellationToken)
        {
            using (CancellationTokenSource cts = cancellationToken.CanBeCanceled ? CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, default(CancellationToken)) : new CancellationTokenSource())
            {
                Task <Task> task = Task.WhenAny(new Task[]
                {
                    asyncWaiter,
                    Task.Delay(millisecondsTimeout, cts.Token)
                });
                object obj   = asyncWaiter;
                Task   task2 = await task.ConfigureAwait(false);

                if (obj == task2)
                {
                    obj = null;
                    cts.Cancel();
                    return(true);
                }
            }
            CancellationTokenSource cts = null;
            object lockObj = this.m_lockObj;

            lock (lockObj)
            {
                if (this.RemoveAsyncWaiter(asyncWaiter))
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    return(false);
                }
            }
            return(await asyncWaiter.ConfigureAwait(false));
        }
Пример #2
0
        private async Task <bool> WaitUntilCountOrTimeoutAsync(SemaphoreSlim.TaskNode asyncWaiter, int millisecondsTimeout, CancellationToken cancellationToken)
        {
            CancellationTokenSource cts = cancellationToken.CanBeCanceled ? CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, new CancellationToken()) : new CancellationTokenSource();

            try
            {
                Task <Task> task1 = Task.WhenAny((Task)asyncWaiter, Task.Delay(millisecondsTimeout, cts.Token));
                object      obj   = (object)asyncWaiter;
                int         num   = 0;
                Task        task2 = await task1.ConfigureAwait(num != 0);

                if (obj == task2)
                {
                    obj = (object)null;
                    cts.Cancel();
                    return(true);
                }
            }
            finally
            {
                if (cts != null)
                {
                    cts.Dispose();
                }
            }
            cts = (CancellationTokenSource)null;
            lock (this.m_lockObj)
            {
                if (this.RemoveAsyncWaiter(asyncWaiter))
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    return(false);
                }
            }
            return(await asyncWaiter.ConfigureAwait(false));
        }