// Testing static async Task Test() { var pts = new PauseTokenSource(); var task = SomeMethodAsync(pts.Token); // sync version Console.WriteLine("Before pause requested"); pts.PauseWithResponseAsync().Wait(); Console.WriteLine("After pause requested, paused: " + pts.Token.IsPaused); pts.PauseWithResponseAsync().Wait(); Console.WriteLine("After pause requested, paused: " + pts.Token.IsPaused); Console.WriteLine("Press enter to resume..."); Console.ReadLine(); pts.Resume(); // async version: Console.WriteLine("Before pause requested"); await pts.PauseWithResponseAsync(); Console.WriteLine("After pause requested, paused: " + pts.Token.IsPaused); await pts.PauseWithResponseAsync(); Console.WriteLine("After pause requested, paused: " + pts.Token.IsPaused); Console.WriteLine("Press enter to resume..."); Console.ReadLine(); pts.Resume(); }
private void Resume() { _crawlerPauseTokenSource.Resume(); _crawlerService.IsPaused = false; _pauseCommand.RaiseCanExecuteChanged(); _resumeCommand.RaiseCanExecuteChanged(); }
static void Main() { var pts = new PauseTokenSource(); var task = SomeMethodAsync(pts.Token); Task.Run(() => { Console.WriteLine("Before pause requested"); pts.PauseWithResponseAsync().Wait(); Console.WriteLine("After pause requested."); pts.Resume(); }).Wait(); Console.ReadLine(); // Alternatively, async version: /* * Func<Task> func = async () => * { * Console.WriteLine("Before pause requested"); * await pts.PauseWithResponseAsync(); * Console.WriteLine("After pause requested."); * pts.Resume(); * }; * func().Wait(); * Console.ReadLine(); */ }
private void Resume() { crawlerPauseToken.Resume(); crawlerService.IsPaused = false; pauseCommand.RaiseCanExecuteChanged(); resumeCommand.RaiseCanExecuteChanged(); }
static async Task Test(CancellationToken token) { var pts = new PauseTokenSource(); var task = DoWorkAsync(pts.Token, token); while (true) { token.ThrowIfCancellationRequested(); Console.WriteLine("Press enter to pause..."); Console.ReadLine(); Console.WriteLine("Before pause requested"); await pts.PauseAsync(); Console.WriteLine("After pause requested, paused: " + pts.IsPaused); Console.WriteLine("Press enter to resume..."); Console.ReadLine(); Console.WriteLine("Before resume"); pts.Resume(); Console.WriteLine("After resume"); } }
public void Resume() { crawlBlogsPause.Resume(); crawlerService.IsPaused = false; pauseCommand.RaiseCanExecuteChanged(); resumeCommand.RaiseCanExecuteChanged(); }
public void NotifyCommandFinished() { _commandExecuting = false; if (IsPaused) { _pts.Resume(); } RaiseCanExecuteChanged(); }
private void buttonPause_Click(object sender, EventArgs e) { if (!paused) { buttonPause.Text = "Возобновить"; myPause.Pause(); paused = true; OnTimerPause(); } else { buttonPause.Text = "Пауза"; myPause.Resume(); paused = false; OnTimerResume(); } }
/// <summary> /// Resume send mail /// </summary> public void ResumeSendBulkMail() { _pauseTokenSource.Resume(); }