/// <summary> /// Stop listening messages from device /// </summary> public virtual void Stop() { if (!IsStarted) { return; } lock (_lock) { if (!IsStarted) { return; } _connection.DataAvailable -= OnDeviceDataAvailable; _connection.Dispose(); IsStarted = false; } }
private void OnRemoveConnection(IBinaryConnection binaryConnection) { DeviceGatewayService deviceGatewayService; if (!_deviceGatewayServicesByConnection.TryGetValue(binaryConnection, out deviceGatewayService)) { binaryConnection.Dispose(); } else { var deviceGuid = deviceGatewayService.DeviceGuid; if (deviceGuid != Guid.Empty) { _deviceService.UnsubscribeFromCommands(deviceGuid.ToString(), deviceGatewayService.DeviceKey); _deviceGatewayServicesByDevice.Remove(deviceGuid); } deviceGatewayService.Stop(); } _deviceGatewayServicesByConnection.Remove(binaryConnection); }