title: Tasks cancellation and continue with
body: <p>I'm perplex on the cancellation of several tasks and continue with a task to display result.
  According to what I understood, this program should display</p>
  <blockquote>
  <p>Tasks canceled</p>
  </blockquote>
  <pre><code>CancellationTokenSource cts = new CancellationTokenSource();
  List&lt;Task&gt; tasks = new List&lt;Task&gt;();
  for(int i= 0; i&lt;3; i++)
  {
      tasks.Add(Task.Run(() =&gt;{
          while(!cts.Token.IsCancellationRequested)
              Thread.Sleep(500);
      
          // Uncomment this to see 'Tasks canceled' in the result
          //if(cts.Token.IsCancellationRequested)
          //    cts.Token.ThrowIfCancellationRequested();
      },cts.Token));
  }
  
  Task.WhenAll(tasks).ContinueWith(task =&gt;
  {
      if(task.IsCanceled)
          Console.WriteLine(&quot;Tasks canceled&quot;);
      if(task.IsCompleted)
          Console.WriteLine(&quot;Tasks completed&quot;);
  });
  Thread.Sleep(2000);
  cts.Cancel();
  </code></pre>
  <p>Unfortunately it display</p>
  <blockquote>
  <p>Tasks completed</p>
  </blockquote>
  <p>If i uncomment the throwing of cancel exception the program display</p>
  <blockquote>
  <p>Tasks canceled</p>
  <p>Tasks completed</p>
  </blockquote>
  <p>Why? it seems that I missed something but I do not see what...</p>