protected override Task BuildSelectedValue(bool withNotifyPropertyChanged = true) { if (CTS != null) { CTS.Cancel(false); } CTS = new CancellationTokenSource(); return(Task.Run(() => { _selectedValue = new ApplyedProductParameter { Id = this.Id, DataType = this.DataType, Values = Items.Where(x => x.Selected).Select(y => new ApplyedProductParameterValue { Id = y.Id }).ToList() }; if (withNotifyPropertyChanged) { RaisePropertyChanged(() => SelectedValue); } }, CTS.Token)); }
public void Cancel() { if (State == TransferStates.CANCELED) { return; } State = TransferStates.CANCELED; CTS?.Cancel(); Message = "Upload was canceled"; }
/// <summary> /// 開放処理。 /// </summary> public void Dispose() { if (CTS == null) { return; } CTS.Cancel(); CTS.Dispose(); CTS = null; }
public MainPageViewModel(INavigationService navigationService, IPageDialogService dialogService) { _navigationService = navigationService; _dialogService = dialogService; GetLocationCommand = new DelegateCommand(async() => { if (GeolocationAccuracySelected == null) { await _dialogService.DisplayAlertAsync("錯誤", "請選擇GPS定位精確度", "確定"); return; } CTS = new CancellationTokenSource(); Token = CTS.Token; GetLocation = true; try { var request = new GeolocationRequest(GeolocationAccuracySelected.Item, TimeSpan.FromSeconds(10)); var location = await Geolocation.GetLocationAsync(request, Token); if (location != null) { YourLocation = $"Latitude 緯度 : {location.Latitude}, Longitude 經度 : {location.Longitude}"; } } catch (FeatureNotSupportedException fnsEx) { // 處理裝置不支援這項功能的例外異常 } catch (PermissionException pEx) { // 處理關於權限上的例外異常 } catch (AggregateException ae) { // 處理取消的例外異常 } catch (Exception ex) { // 無法取得該GPS位置之例外異常 } GetLocation = false; }); CancelLocationCommand = new DelegateCommand(() => { GetLocation = false; CTS.Cancel(); }); }
protected Task BuildSelectedValue() { if (CTS != null) { CTS.Cancel(false); } CTS = new CancellationTokenSource(); return(Task.Run(() => { SelectedValue = new ApplyedFilter { Id = this.Id, DataType = this.DataType, Values = Items.Where(x => x.Selected).Select(y => new ApplyedFilterValue { Id = y.Id }).ToList() }; }, CTS.Token)); }
protected Task BuildSelectedValue(PickerCollectionItemVM item) { if (CTS != null) { CTS.Cancel(false); } CTS = new CancellationTokenSource(); return(Task.Run(() => { SelectedValue = new ApplyedProductParameter { Id = this.Id, DataType = this.DataType, Values = new List <ApplyedProductParameterValue> { new ApplyedProductParameterValue { Id = item.Id } } }; }, CTS.Token)); }
private static void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e) { CTS.Cancel(); }
/// Cancel communication throughout pipe public virtual void Disconnect() { Connected = false; CTS?.Cancel(); }
public void LoadRom(string romFile, bool prompt) { try { CTS?.Cancel(); Emulator?.Stop(); DisplayTask?.Wait(); if (prompt) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Title = Resources.OpenTitle; if (File.Exists(romFile)) { dialog.InitialDirectory = Path.GetDirectoryName(romFile); dialog.FileName = Path.GetFileName(romFile); } romFile = dialog.ShowDialog() == DialogResult.OK ? dialog.FileName : ""; } if (!string.IsNullOrWhiteSpace(romFile) && File.Exists(romFile)) { LastRomFile = romFile; Log($"Loading ROM: {romFile}", LogLevel.Info); byte[] romData = File.ReadAllBytes(romFile); Emulator = new Chip8Emu(this, romData); DisplayBuffer = new bool[Chip8Emu.DisplayColumns, Chip8Emu.DisplayRows]; Emulator.TryConfigureQuirks(); Log("Ready.", LogLevel.Info); } CTS = new CancellationTokenSource(); Emulator?.Start(CTS); DisplayTask = Task.Factory.StartNew(() => { Stopwatch sw = new Stopwatch(); sw.Start(); while (!CTS.Token.IsCancellationRequested) { if (sw.Elapsed >= ViewDelay) { DrawDisplay(); sw.Restart(); } Thread.Yield(); } }); } catch (Exception ex) { HandleException(ex); } finally { UpdateConfig(); } }
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { CTS?.Cancel(); Emulator?.Stop(); DisplayTask?.Wait(); }