public async void Disconnect() { disconnecting = true; connected = false; if (_buttonService != null) { using (_buttonService) { _buttonService.Error -= OnServiceError; _buttonService.ConnectionChanged -= OnConnectionChanged; _buttonService = null; } } if (_accelService != null) { using (_accelService) { try { _accelService.Error -= OnServiceError; _accelService.ConnectionChanged -= OnConnectionChanged; await _accelService.StopReading(); } catch { } _accelService = null; } } }
private async Task <bool> ConnectAccelerometerService() { if (_accelService == null) { _accelService = new BleAccelerometerService() { Version = this.version }; _accelService.Error += OnServiceError; if (await _accelService.ConnectAsync(deviceInfo.ContainerId)) { _accelService.ConnectionChanged += OnConnectionChanged; return(true); } _accelService.Error -= OnServiceError; _accelService = null; return(false); } return(true); }