title: What is the proper way to chain Tasks when returning a Task?
body: <p>I am so so with using Tasks in C# but I get confused when I try to return a Task from a method and that method will do multiple tasks within itself. So do I have my method spin up a new Task and then do everything sequentially inside of there? It's hard to wrap my head around doing it all with  .ContinueWith()</p>
  
  <p>Example:</p>
  
  <pre><code>public Task&lt;string&gt; GetSomeData(CancellationToken token)
  {
      return Task.Factory.StartNew(() =&gt;
      {
          token.ThrowIfCancellationRequested();
  
          var initialData = GetSomeInteger(token).Result;
  
          return GetSomeString(initialData, token).Result;
      });
  }
  
  public Task&lt;int&gt; GetSomeInteger(CancellationToken token)
  {
      return Task&lt;int&gt;.Factory.StartNew(() =&gt;
      {
          return 4;
      }, token);
  }
  
  public Task&lt;string&gt; GetSomeString(int value, CancellationToken token)
  {
      return Task&lt;string&gt;.Factory.StartNew(() =&gt;
      {
          return value.ToString();
      }, token);
  }
  </code></pre>
  
  <p>I am unsure how else to write this method to make it use Tasks correctly. I guess I just feel like there should be a .ContinueWith in there or something.</p>
  
  <p>Possible fix??</p>
  
  <pre><code>public Task&lt;string&gt; GetSomeData(CancellationToken token)
  {
      return GetSomeInteger(token).ContinueWith((prevTask) =&gt;
      {
          return GetSomeString(prevTask.Result, token);
      }, token).Unwrap();
  }
  </code></pre>