Interop with Other Asynchronous Patterns and Types
.NEXT Threading library simplifies interop between Task-based programming model and other asynchronous patterns. Bridge methods located in AsyncBridge class.
Cancellation Token
If you have only CancellationToken and you need to synchronize with its cancellation then use WaitAsync
extension method to do that. It converts token into awaitable object.
using DotNext.Threading;
using System.Threading;
CancellationToken token = ...;
await token.WaitAsync();
Wait Handles
WaitHandle represents OS-specific object that wait for exclusive access to shared resources. It can be converted into awaitable object using WaitAsync
static method.
using DotNext.Threading;
using System.Threading;
var resetEvent = new ManualResetEvent(false);
await resetEvent.WaitAsync();