IDesktopNetworkStatus interface

Namespace Runic.Platform in Runic.Platform 0.23.0

public interface IDesktopNetworkStatus : IAsyncDisposable

Inherits or implements IAsyncDisposable.

The computer's network status: online, metered and captive portal, read once or watched.

Remarks

An application-scoped service that needs no window. Results and watch items arrive on the thread pool. Dispose it at shutdown; that ends its watches.

Methods

ReadAsync

ValueTask<PlatformResult<DesktopNetworkState>> ReadAsync(CancellationToken cancellationToken = default)

Reads the current network state.

Parameters

cancellationToken

Cancels waiting for the answer.

Returns

The state, or Unavailable when the platform has no network status source.

Exceptions

ObjectDisposedException

The service was disposed.

WatchAsync

IAsyncEnumerable<PlatformResult<DesktopNetworkState>> WatchAsync(CancellationToken cancellationToken = default)

Reports the current network state, then each change.

Parameters

cancellationToken

Ends the watch, which then throws OperationCanceledException.

Exceptions

ObjectDisposedException

The service was disposed.

Remarks

A change that leaves the state as it was is not reported. When the status source goes away, such as a desktop portal that stopped, the watch reports Unavailable and continues with a fresh state once it is back. Without a source the watch reports Unavailable once and then waits. Disposing the service ends the watch.