You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A lot of developers start using this library for AsyncLock, an async-compatible mutual exclusion mechanism. Using AsyncLock is straightforward:
privatereadonlyAsyncLock_mutex=newAsyncLock();publicasyncTaskUseLockAsync(){// AsyncLock can be locked asynchronouslyusing(await_mutex.LockAsync()){// It's safe to await while the lock is heldawaitTask.Delay(TimeSpan.FromSeconds(1));}}
AsyncLock also fully supports cancellation:
publicasyncTaskUseLockAsync(){// Attempt to take the lock only for 2 seconds.varcts=newCancellationTokenSource(TimeSpan.FromSeconds(2));// If the lock isn't available after 2 seconds, this will// raise OperationCanceledException.using(await_mutex.LockAsync(cts.Token)){awaitTask.Delay(TimeSpan.FromSeconds(1));}}
AsyncLock also has a synchronous API. This permits some threads to acquire the lock asynchronously while other threads acquire the lock synchronously (blocking the thread).
AsyncLock is just the beginning. The AsyncEx library contains a full suite of coordination primitives: AsyncManualResetEvent, AsyncAutoResetEvent, AsyncConditionVariable, AsyncMonitor, AsyncSemaphore, AsyncCountdownEvent, and AsyncReaderWriterLock.
AsyncEx v4 supported .NET 4.0, Windows Store 8.1, Windows Phone Silverlight 8.0, Windows Phone Applications 8.1, and Silverlight 5.0. Support for these platforms has been dropped with AsyncEx v5.
AsyncEx v3 supported Windows Store 8.0, Windows Phone Silverlight 7.5, and Silverlight 4.0. Support for these platforms has been dropped with AsyncEx v4.