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> ConnectButtonService() { if (_buttonService == null) { _buttonService = new BleButtonService() { Version = this.version }; _buttonService.Error += OnServiceError; if (await _buttonService.ConnectAsync(deviceInfo.ContainerId)) { _buttonService.ConnectionChanged += OnConnectionChanged; return(true); } _buttonService.Error -= OnServiceError; _buttonService = null; return(false); } return(true); }