コード例 #1
0
ファイル: TaskExtensions.cs プロジェクト: yuts/PTVS
        public static async Task <IDisposable> LockAsync(this SemaphoreSlim semaphore, CancellationToken cancellationToken)
        {
            var res = new SemaphoreLock(semaphore);

            try {
                await semaphore.WaitAsync(cancellationToken);

                var res2 = res;
                res = null;
                return(res2);
            } finally {
                res?.Reset();
            }
        }
コード例 #2
0
        public static IDisposable Lock(this SemaphoreSlim semaphore)
        {
            var res = new SemaphoreLock(semaphore);

            try {
                try {
                    semaphore.Wait();
                    var res2 = res;
                    res = null;
                    return(res2);
                } finally {
                    res?.Reset();
                }
            } catch (ObjectDisposedException ex) {
                throw new OperationCanceledException("semaphore was disposed", ex);
            }
        }
コード例 #3
0
        public static async Task <IDisposable> LockAsync(this SemaphoreSlim semaphore, CancellationToken cancellationToken)
        {
            var res = new SemaphoreLock(semaphore);

            try {
                try {
                    await semaphore.WaitAsync(cancellationToken);

                    var res2 = res;
                    res = null;
                    return(res2);
                } finally {
                    res?.Reset();
                }
            } catch (ObjectDisposedException ex) {
                throw new OperationCanceledException("semaphore was disposed", ex);
            }
        }