Here is my problem: I am canceling the task with a Click event that works fine. Now I want to restart the task by clicking on the same start event that originally launched the task. The βerrorβ I get is that I get MessageBox (βStop Clickedβ) information. Therefore Im "stuck" in the Cleanup Task.
How can i solve this? Help is much appreciated.
Thanks!
Here is my code:
public partial class MainWindow { CancellationTokenSource cts = new CancellationTokenSource(); ParallelOptions po = new ParallelOptions(); } private void Start_Click(object sender, RoutedEventArgs e) { var uiScheduler = TaskScheduler.FromCurrentSynchronizationContext(); CancellationToken token = cts.Token; ParallelOptions po = new ParallelOptions(); po.CancellationToken = cts.Token; po.MaxDegreeOfParallelism = System.Environment.ProcessorCount; Task dlTask = Task.Factory.StartNew(() => { do { token.ThrowIfCancellationRequested(); Parallel.For(0, dicQueryNoQueryURL.Count, po , i => { token.ThrowIfCancellationRequested(); if (!token.IsCancellationRequested){
source share