The Nito.AsyncEx library includes many types and extension methods. To avoid conflicts, all of these types are defined in the
Nito.AsyncEx namespace.
Asynchronous Coordination Primitives
There is a whole suite of
async-ready coordination primitives. Cancellation is supported for all asynchronous operations that change state.
Most people just need
AsyncLock, but Nito.AsyncEx also includes
AsyncManualResetEvent,
AsyncAutoResetEvent,
AsyncConditionVariable,
AsyncMonitor,
AsyncSemaphore,
AsyncCountdownEvent,
AsyncBarrier, and
AsyncReaderWriterLock.
Asynchronous and Concurrent Collections
AsyncProducerConsumerQueue is an
async-ready producer/consumer queue that works on all platforms.
AsyncCollection is an
async-compatible wrapper around
IProducerConsumerCollection, in the same way that
BlockingCollection is a blocking wrapper around
IProducerConsumerCollection.
You can also use
ProducerProgress to send
IProgress updates to a producer/consumer collection.
Utility Types and Methods
The
AsyncLazy class provides support for
asynchronous lazy initialization.
You can use
IEnumerable<Task<T>>.OrderByCompletion to order tasks by when they complete.
The
AsyncContext class and the related
AsyncContextThread class provide contexts for asynchronous operations for situations where such a context is lacking (Console applications and Win32 services). Note that due to security restrictions,
AsyncContext and AsyncContextThread will not work on Silverlight or Windows Phone platforms.
CancellationTokenHelpers provides some static methods and constants for working with
CancellationTokens.
DeferralManager simplifies the writing of "command-style" events that provide a
GetDeferral method.
NotifyTaskCompletion is a data-binding-friendly wrapper for a
Task, providing property-change notifications when the task completes.
Interop
TaskCompletionSource is a non-generic version of the built-in
TaskCompletionSource<TResult>.
The
AsyncFactory classes interoperate between Task-based Asynchronous Programming (
async) and the Asynchronous Programming Model (
IAsyncResult).
AsyncFactory<T> can also create wrapper tasks for most events.
TaskCompletionSourceExtensions includes
TryCompleteFromEventArgs, which helps interoperate between Task-based Asynchronous Programming (
async) and Event-based Asynchronous Programming (
*Completed).
Miscellaneous
TaskConstants provides static constant
Task<TResult> values that are useful when taking advantage of the
async fast path.
You can respond to task progress updates by using one of the implementations of
IProgress:
PropertyProgress,
ObserverProgress,
ProducerProgress, or
DataflowProgress.
Extension Methods
CancellationToken.AsTask will create a task that is canceled when a
CancellationToken is canceled.
TaskCompletionSourceExtensions has several extension methods for
TaskCompletionSource, including propagating results from a completed
Task or
AsyncCompletedEventArgs, and for completing the source forcing background continuations.
Extension methods for the Task type include ordering tasks by completion and waiting while unwrapping exceptions (or without observing exceptions).
TaskFactoryExtensions adds
Run overloads to task factories.
Dataflow Support
There is currently only one Dataflow block in the library:
FuncBlock, which allows an
async function to provide data to a dataflow mesh with full cooperative cancellation and error propagation.
Low-Level Building Blocks
ExceptionHelpers.PrepareForRethrow will preserve the stack trace when rethrowing any exception.
For dealing with
SynchronizationContext directly, the library provides
CurrentOrDefault and SynchronizationContextSwitcher.