title: Cancelling a task throws 'A task was cancelled' AggregateException. Why?
body: <p>I created a simple TaskManager that keeps track of running tasks and their cancellation tokens.  My code snippet uses it to cancel the specified tasks, I then wait until they complete.  Straightforward and my code works - almost - as expected.</p>
  <p>The unexplainable part of the code is the <code>Task.WaitAll</code> call.  It throws an <code>AggregateException</code> with three 'A task was cancelled' inner exception.  This is true of course, but why does it throw an exception?  Here is the code:</p>
  <pre><code>internal void StopProcessor()
  {       
      try
      {   
          var taskList = _taskManager.CancelTask(new string[] { &quot;InboundProcessor&quot;, &quot;OutboundProcessor&quot;, &quot;MainProcessor&quot; });
          
          Task.WaitAll(taskList, 2000);
      }
      catch (Exception)
      {
          foreach (var t in _taskManager.GetAllTasks())
          {
              Console.WriteLine($&quot;Task ID={t.Task.Id}, status={t.Task.Status}, cancelled={t.Task.IsCanceled}, completed={t.Task.IsCompleted}, faulted={t.Task.IsFaulted}&quot;);
          }
      }
  }
  </code></pre>
  <p>When I check the task status details in the catch block, I get the result I expected, all tasks have a status=cancelled, completed=True and no fault:</p>
  <ul>
  <li><p>Task ID=17, status=Canceled, cancelled=True, completed=True, faulted=False</p>
  </li>
  <li><p>Task ID=19, status=Canceled, cancelled=True, completed=True, faulted=False</p>
  </li>
  <li><p>Task ID=21, status=Canceled, cancelled=True, completed=True, faulted=False</p>
  </li>
  </ul>
  <p>I don't understand the reason for this behavior, can someone educate me and tell me how to improve this code?  Thanks.</p>