public async Task StartLockWorkStationAsync() { _imminentLocking = true; var viewModel = GetViewModel(); Show(); var token = _cancellationTokenSource.Token; for (int i = 1000; i >= 0; i--) { viewModel.CentiSeconds = i; viewModel.Seconds = i / 100; try { await Task.Delay(10, token); } catch (TaskCanceledException) { Hide(); _imminentLocking = false; return; } if (token.IsCancellationRequested) { Hide(); _imminentLocking = false; return; } } Hide(); SessionLock.LockSession(); _imminentLocking = false; }
private void LockButton_Click(object sender, RoutedEventArgs e) { Interlocked.Exchange(ref _cancellationTokenSource, new CancellationTokenSource()).Cancel(); SessionLock.LockSession(); }