public static IDisposable LockSync(this SemaphoreSlim semaphore) { if (semaphore == null) { throw new ArgumentNullException(nameof(semaphore)); } var wrapper = new AutoReleaseSemaphoreWrapper(semaphore); semaphore.Wait(); return(wrapper); }
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); }