private void Control() { var sensorStatus = _sensor.Status; if (sensorStatus == SensorStatus.Offline) { _cts = new CancellationTokenSource(); _sensor.Connect(_cts.Token); } else if (sensorStatus == SensorStatus.Online) { _sensor.Disconnect(CancellationToken.None); if (_cts != null) { _cts.Dispose(); _cts = null; } } else if (_cts != null) { _cts.Cancel(); _cts.Dispose(); _cts = null; } }