public override async void OnDisappearing() { _isDisappearing = true; _disappearingTokenSource.Cancel(); if (_connectionTokenSource != null && _connectionTask != null) { _connectionTokenSource.Cancel(); await _connectionTask; } await Device.DisconnectAsync(); }
public override async void OnDisappearing() { _isDisappearing = true; _disappearingTokenSource.Cancel(); Device.DeviceStateChanged -= DeviceStateChangedHandler; if (_connectionTokenSource != null) { _connectionTokenSource.Cancel(); await _connectionTask; } await Device.DisconnectAsync(); }
private async Task ConnectAsync() { while (!_connectionTokenSource.IsCancellationRequested) { if (Device.DeviceState != DeviceState.Connected) { var connectionResult = DeviceConnectionResult.Ok; var dialogResult = 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("ConnectingTo"), Device.Name, Translate("Cancel"), _connectionTokenSource.Token); if (dialogResult.IsCancelled) { await Device.DisconnectAsync(); if (!_isDisappearing) { await NavigationService.NavigateBackAsync(); } return; } else { if (connectionResult == DeviceConnectionResult.Error) { await _dialogService.ShowMessageBoxAsync( Translate("Warning"), Translate("FailedToConnect"), Translate("Ok"), _disappearingTokenSource.Token); if (!_isDisappearing) { await NavigationService.NavigateBackAsync(); } return; } else { if (Device.DeviceType == DeviceType.BuWizz) { SetBuWizzOutputLevel(BuWizzOutputLevel); } else if (Device.DeviceType == DeviceType.BuWizz2) { SetBuWizzOutputLevel(BuWizz2OutputLevel); } } } } else { await Task.Delay(50); } } }