Interface IDeviceConnection<T>
Represents a specific connection to a device, via ConnectAsync(CancellationToken).
public interface IDeviceConnection<T>
Type Parameters
TThe type of the device-specific connection object.
Remarks
This represents a particular connection in time. Each time a connection is established with a device, that connection will be represented by a unique IDeviceConnection<T>.
Implementations are expected to be thread-safe.
Properties
CloseError
Gets the exception representing the connection lost error, or null if the connection has not closed or it was closed via DisconnectAsync(CancellationToken).
Exception? CloseError { get; }
Property Value
Remarks
Connection
Gets the device-specific connection object.
T Connection { get; }
Property Value
- T
HasClosed
Gets whether this connection has closed.
bool HasClosed { get; }
Property Value
Remarks
Note that while this might be true, reflecting that this connection was closed, a new connection with this same device might already be reestablished. This reflects the state of this connection, not necessarily the current device connection state.
Methods
RegisterClosedCallback(Action<Exception?, object?>, object?)
Registers a callback for when the connection closes.
IDisposable RegisterClosedCallback(Action<Exception?, object?> callback, object? state)
Parameters
callbackAction<Exception, object>The callback, with the first parameter being the exception representing the connection lost error (i.e., CloseError) if the connection was not closed gracefully, and the second parameter being the state object (
state).stateobjectA state object that will be passed to the callback.
Returns
- IDisposable
A IDisposable that can be used to unregister this callback.
Remarks
Callbacks might happen on any thread.
If the connection has already previously been closed, callback will immediately be called synchronously.
Exceptions
- ArgumentNullException
callbackis null.