private async Task ConnectAsync() { _connectionTokenSource = new CancellationTokenSource(); DeviceConnectionResult connectionResult = DeviceConnectionResult.Ok; await _dialogService.ShowProgressDialogAsync( false, async (progressDialog, token) => { using (token.Register(() => _connectionTokenSource?.Cancel())) { connectionResult = await Device.ConnectAsync( _reconnect, OnDeviceDisconnected, Enumerable.Empty <ChannelConfiguration>(), true, true, _connectionTokenSource.Token); } }, Translate("Connecting"), null, Translate("Cancel")); _connectionTokenSource.Dispose(); _connectionTokenSource = null; if (Device.DeviceState == DeviceState.Connected) { _reconnect = true; if (Device.DeviceType == DeviceType.BuWizz) { SetBuWizzOutputLevel(BuWizzOutputLevel); } else if (Device.DeviceType == DeviceType.BuWizz2) { SetBuWizzOutputLevel(BuWizz2OutputLevel); } } else { if (!_isDisappearing) { if (connectionResult == DeviceConnectionResult.Error) { await _dialogService.ShowMessageBoxAsync( Translate("Warning"), Translate("FailedToConnect"), Translate("Ok"), _disappearingTokenSource.Token); } await NavigationService.NavigateBackAsync(); } } }
private async Task ConnectAsync() { _connectionTokenSource = new CancellationTokenSource(); DeviceConnectionResult connectionResult = DeviceConnectionResult.Ok; await _dialogService.ShowProgressDialogAsync( false, async (progressDialog, token) => { token.Register(() => _connectionTokenSource.Cancel()); connectionResult = await Device.ConnectAsync(_connectionTokenSource.Token); }, "Connecting...", null, "Cancel"); _connectionTokenSource.Dispose(); _connectionTokenSource = null; if (Device.DeviceState == DeviceState.Connected) { if (Device.DeviceType == DeviceType.BuWizz) { SetBuWizzOutputLevel(BuWizzOutputLevel); } else if (Device.DeviceType == DeviceType.BuWizz2) { SetBuWizzOutputLevel(BuWizz2OutputLevel); } } else { if (!_isDisappearing) { if (connectionResult == DeviceConnectionResult.Error) { await _dialogService.ShowMessageBoxAsync("Warning", "Failed to connect to device.", "Ok", _disappearingTokenSource.Token); } await NavigationService.NavigateBackAsync(); } } }