public interface IDesktopNetworkStatus : 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
cancellationTokenCancels waiting for the answer.
Returns
The state, or Unavailable when the platform has no network status source.
Exceptions
ObjectDisposedExceptionThe service was disposed.
WatchAsync
IAsyncEnumerable<PlatformResult<DesktopNetworkState>> WatchAsync(CancellationToken cancellationToken = default) Reports the current network state, then each change.
Parameters
cancellationTokenEnds the watch, which then throws
OperationCanceledException.
Exceptions
ObjectDisposedExceptionThe 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.