<PackageReference Include="Nito.AsyncEx.Coordination" Version="5.0.0" />

Nito.AsyncEx.AsyncMonitor

public sealed class AsyncMonitor
An async-compatible monitor.
public int Id { get; }

Gets a semi-unique identifier for this monitor.

public AsyncMonitor()

Constructs a new monitor.

public IDisposable Enter(CancellationToken cancellationToken)

Synchronously enters the monitor. Returns a disposable that leaves the monitor when disposed. This method may block the calling thread.

public IDisposable Enter()

Asynchronously enters the monitor. Returns a disposable that leaves the monitor when disposed. This method may block the calling thread.

public AwaitableDisposable<IDisposable> EnterAsync(CancellationToken cancellationToken)

Asynchronously enters the monitor. Returns a disposable that leaves the monitor when disposed.

public AwaitableDisposable<IDisposable> EnterAsync()

Asynchronously enters the monitor. Returns a disposable that leaves the monitor when disposed.

public void Pulse()

Sends a signal to a single task waiting on this monitor. The monitor MUST already be entered when calling this method, and it will still be entered when this method returns.

public void PulseAll()

Sends a signal to all tasks waiting on this monitor. The monitor MUST already be entered when calling this method, and it will still be entered when this method returns.

public void Wait(CancellationToken cancellationToken)

Asynchronously waits for a pulse signal on this monitor. This method may block the calling thread. The monitor MUST already be entered when calling this method, and it will still be entered when this method returns, even if the method is cancelled. This method internally will leave the monitor while waiting for a notification.

public void Wait()

Asynchronously waits for a pulse signal on this monitor. This method may block the calling thread. The monitor MUST already be entered when calling this method, and it will still be entered when this method returns. This method internally will leave the monitor while waiting for a notification.

public Task WaitAsync(CancellationToken cancellationToken)

Asynchronously waits for a pulse signal on this monitor. The monitor MUST already be entered when calling this method, and it will still be entered when this method returns, even if the method is cancelled. This method internally will leave the monitor while waiting for a notification.

public Task WaitAsync()

Asynchronously waits for a pulse signal on this monitor. The monitor MUST already be entered when calling this method, and it will still be entered when this method returns. This method internally will leave the monitor while waiting for a notification.