A helper library for async/await.
Note: This README is for AsyncEx v5 (the current version). For AsyncEx v4, see here.
Supports netstandard1.3 (including .NET 4.6, .NET Core 1.0, Xamarin.iOS 10, Xamarin.Android 7, Mono 4.6, and Universal Windows 10).
Install the NuGet package.
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).
publicasyncTaskUseLockAsync(){using(await_mutex.LockAsync()){awaitTask.Delay(TimeSpan.FromSeconds(1));}}publicvoidUseLock(){using(_mutex.Lock()){Thread.Sleep(TimeSpan.FromSeconds(1));}}AsyncLock is just the beginning. The AsyncEx library contains a full suite of coordination primitives: AsyncManualResetEvent, AsyncAutoResetEvent, AsyncConditionVariable, AsyncMonitor, AsyncSemaphore, AsyncCountdownEvent, and AsyncReaderWriterLock.
There's quite a few other helpful types; see the docs for full details
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.
