title: Task Cancelled Exception (ThrowForNonSuccess)
body: <p>This is a continuation from this question:
  <a href="https://stackoverflow.com/questions/21154692/task-continuiation">Multiple Task Continuation</a></p>
  
  <p>I have changed my code as in the answer, however now I am receiving <code>TaskCancelledExceptions</code> when I try to run tasks.</p>
  
  <pre><code>public virtual async Task RunAsync(TaskWithProgress task)
  {
      Show();
      TaskIsRunning();
      await SetCompletedHandler(TaskComplete());
      await SetCancelledHandler(TaskCancelled())
      await SetFaultedHandler(TaskFaulted());
      await task;
      Close();
  }
  </code></pre>
  
  <p>however the following code does not. I am a bit stuck as to why.</p>
  
  <pre><code>public virtual Task RunAsync(TaskWithProgress task)
  {
      Show();
      TaskIsRunning();
      SetCompletedHandler(TaskComplete());
      SetCancelledHandler(TaskCancelled())
      SetFaultedHandler(TaskFaulted());
      return task;
  }
  </code></pre>
  
  <p>The calling code basically involves the following:</p>
  
  <pre><code>await progressDialog.RunAsync(task);
  </code></pre>
  
  <p>Edit:</p>
  
  <p>I do not cancel a <code>cancellationtoken</code> anywhere so I can't see why this is throwing that exception.</p>
  
  <p>The three SetXXXHandler() methods basically perform the following code with different continuation status:</p>
  
  <pre><code>task.ContinueWith(_ =&gt; action(), CancellationToken.None, TaskContinuationOptions.OnlyOnCanceled, this.Scheduler);
  </code></pre>
  
  <p>The Stack trace is here:</p>
  
  <pre><code>   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
     at FugroDXExt.frmBaseProgressAsync.&lt;RunAsync&gt;d__7.MoveNext() in d:\C#\FugroDXExt\trunk\frmBaseProgressAsync.cs:line 92
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
     at FCP.Forms.frmProcessing.&lt;mnuApplyCenteredSmoothing_ItemClick&gt;d__34.MoveNext() in d:\C#\FCP\FCP\Forms\frmProcessing.cs:line 578
  </code></pre>
  
  <p><code>Close()</code> simply closes the form. If I remove that line the same thing occurs.</p>