Interface IDeviceConnection
Represents a specific connection to a device, via ConnectAsync(CancellationToken).
public interface IDeviceConnection
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.
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
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
callback
Action<Exception, object>The callback, with the first parameter being the exception representing the connection lost error (i.e., CloseError), and the second parameter being the state object (
state
).state
objectA 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
callback
is null.