title: Stopping Multiple Tasks
body: <p>I'm using the following method to create new Tasks and do long time taking operations in background.If a certain condition is met,I need to completely stop all the tasks and show the user a message.</p>
  
  <pre><code>dowork()
  {
  
      mylist = new List&lt;DataModel.CheckData&gt;();
      int index = 0;
      foreach (var line in mylist)
      {
          mylist.Add(new DataModel.CheckData() { RawLine = line, data = line,FileName=virtualfilelist[index].ToString() });
          index++;
      }
  
      BlockingCollection&lt;DataModel.CheckData&gt; ujobs = new BlockingCollection&lt;DataModel.CheckData&gt;();
      timerRefreshUi.Start();
  
      Task.Factory.StartNew(() =&gt;
      {
          _dtRows.Clear();
          uiQueue.Clear();
          uiQueueBad.Clear();
          uiQueueGood.Clear();
  
          for (int i = 0; i &lt; mylist.Count; i++)
          {
               AddResultRow(mylist[i].data, "Waiting...",mylist[i].FileName, Color.White);
               ujobs.TryAdd(new DataModel.CheckData() { RowId = i, data = mylist[i].data }, 1000);
  
           }
           List&lt;Task&gt; openCheckTasks = new List&lt;Task&gt;();
  
           while (ujobs.Count &gt; 0)
           {
               while (openCheckTasks.Where(task =&gt; task.Status == TaskStatus.Running).ToList().Count &gt;= threadcount)
                System.Threading.Thread.Sleep(250);
  
                Task t = new Task(new Action(() =&gt;
                {
  
                }));
  
                openCheckTasks.Add(t);
                t.Start();
           }
           Task.WaitAll(openCheckTasks.ToArray());
  
      }).ContinueWith(task =&gt; {
          _benchmark.Stop();
          this.BeginInvoke(new Action(() =&gt;
          {
  
          }));
  
      });
  
  }
  </code></pre>
  
  <p>I have tried using <code>Cancellation Token</code> and <code>break</code> in the while loop.But it is not working properly.Please advice the best way to stop all the threads.I have very little experience with Multiple Thread Programming.</p>