title: Task.WhenAny - A Task was Cancelled
body: <p>In the following code:</p>
  
  <pre><code>        if (await Task.WhenAny(task, Task.Delay(100)) == task) {
              success = true;
          }
          else {
              details += "Timed out on SendGrid.";
              await task.ContinueWith(s =&gt;
              {
                  LogError(s.Exception);
              }, TaskContinuationOptions.OnlyOnFaulted);
          }
  </code></pre>
  
  <p>I occasionally get <code>A task was cancelled</code> at the call to <code>await task.ContinueWith</code>.  My goal here is to see if the <code>task</code> completes within 100ms - if it doesn't, I want to handle some logging (this particular task has a resource leak so I'm trying to work around it by wrapping it in a timeout).  This is being pulled from the guidance here:  <a href="https://stackoverflow.com/questions/43170246/debugging-task-whenany-and-push-notifications">Debugging Task.WhenAny and Push Notifications</a></p>
  
  <p>Why is this happening, and what can I do to prevent this exception from being thrown?</p>