title: How to create a generic Task.ContinueWith extension method
body: <p>So currently I have a <code>Task.ContinueWith</code> extensions method like so:</p>
  
  <pre><code>public static Task ContinueWith_UsingSyncContextWorkaround(this Task task, Action&lt;Task&gt; continuationAction, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler, SynchronizationContext sc)
  {
      Action&lt;Task&gt; actionWithWorkaround = t =&gt;
      {
          SynchronizationContext.SetSynchronizationContext(sc);
          continuationAction(t);
      };
  
      return task.ContinueWith(actionWithWorkaround, cancellationToken, continuationOptions, scheduler);
  }
  </code></pre>
  
  <p>and this works fine but it doesn't give me access to the result of the <code>Task</code> so I would like to create a generic extension method.</p>
  
  <p>I have tried:</p>
  
  <pre><code>public static Task&lt;T&gt; ContinueWith_UsingSyncContextWorkaround(this Task&lt;T&gt; task, Action&lt;Task&lt;T&gt;&gt; continuationAction, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler, SynchronizationContext sc)
  {
      Action&lt;Task&lt;T&gt;&gt; actionWithWorkaround = t =&gt;
      {
          SynchronizationContext.SetSynchronizationContext(sc);
          continuationAction(t);
      };
  
      return task.ContinueWith(actionWithWorkaround, cancellationToken, continuationOptions, scheduler);
  }
  </code></pre>
  
  <p>But this won't compile because </p>
  
  <blockquote>
    <p>The type or namespace name T could not be found</p>
  </blockquote>
  
  <p>How do I create a generic <code>Task.ContinueWith</code> extension method?</p>