title: Task.ContinueWith confusion
body: <p>With ASP.NET 4.5 I'm trying to play with the new async/await toys. I have a IDataReader-implementing class that wraps a vendor-specific reader (like SqlDatareader). I have a simple ExecuteSql() method that operates synchronously like so:</p>
  
  <pre><code>public IDataReader ReaderForSql(string sql)
  {
      var cmd = NewCommand(sql, CommandType.Text);
      return DBReader.ReaderFactory(cmd.ExecuteReader());
  }
  </code></pre>
  
  <p>What I want is an Async version of this. Here's my first try:</p>
  
  <pre><code>public Task&lt;IDataReader&gt; ReaderForSqlAsync(string sql, CancellationToken ct)
  {
      var cmd = NewCommand(sql, CommandType.Text);
      return cmd.ExecuteReaderAsync(ct)
                .ContinueWith(t =&gt; DBReader.ReaderFactory(t.Result));
  }
  </code></pre>
  
  <p>and I use it:</p>
  
  <pre><code>using (var r = await connection.ReaderForSqlAsync("SELECT ...", cancellationToken))
  {
      ...
  }
  </code></pre>
  
  <p>This works great in my limited testing so far. But after watching this Cloud9 video a few times: <a href="http://channel9.msdn.com/Events/aspConf/aspConf/Async-in-ASP-NET">http://channel9.msdn.com/Events/aspConf/aspConf/Async-in-ASP-NET</a> I got worreid about warnings they gave regarding:</p>
  
  <ul>
  <li>ContinueWith consuming extra threadpool resources - Readerfactory is very light!</li>
  <li>Task.Result blocking</li>
  </ul>
  
  <p>and since I am passing a ContinuationToken to ExecuteReaderAsync() it seems cancellation is just yet another reason ExecuteReaderAsync() could fail (it's SQL after all!) </p>
  
  <p>What will be the state of the task when I try to ContinueWith it? Will t.Result block? throw? do the wrong thing?</p>