Class DeviceConnection
A default implementation for IDeviceConnection.
public class DeviceConnection : IDeviceConnection
- Inheritance
-
DeviceConnection
- Implements
- Inherited Members
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).
public Exception CloseError { get; }
Property Value
Remarks
HasClosed
Gets whether this connection has closed.
public 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.
public 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), 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.
SignalClosed(Exception)
Signals that the connection has been closed. This should only ever be called once on each instance.
public void SignalClosed(Exception closeError)
Parameters
closeErrorExceptionThe exception representing the connection lost error, or null if the connection was closed gracefully via DisconnectAsync(CancellationToken).
Exceptions
- InvalidOperationException
This connection has already been signaled as closed.