示例#1
0
        public static IDisposable LockSync(this SemaphoreSlim semaphore)
        {
            if (semaphore == null)
            {
                throw new ArgumentNullException(nameof(semaphore));
            }

            var wrapper = new AutoReleaseSemaphoreWrapper(semaphore);

            semaphore.Wait();
            return(wrapper);
        }
示例#2
0
        public static async Task <IDisposable> LockAsync(this SemaphoreSlim semaphore)
        {
            if (semaphore == null)
            {
                throw new ArgumentNullException(nameof(semaphore));
            }

            var wrapper = new AutoReleaseSemaphoreWrapper(semaphore);
            await semaphore.WaitAsync();

            return(wrapper);
        }