title: Best way to convert callback-based async method to awaitable task
body: <p>What would be the best way to convert/wrap a "classic" asynchronous method that uses a callback to something that returns a (awaitable) Task?</p>
  
  <p>For example, given the following method:</p>
  
  <pre><code>public void GetStringFromUrl(string url, Action&lt;string&gt; onCompleted);
  </code></pre>
  
  <p>The only way I know of to wrap this into a method returning a task is:</p>
  
  <pre><code>public Task&lt;string&gt; GetStringFromUrl(string url)
  {
       var t = new TaskCompletionSource&lt;string&gt;();
  
       GetStringFromUrl(url, s =&gt; t.TrySetResult(s));
  
       return t.Task;
  }
  </code></pre>
  
  <p>Is this the only way to accomplish this? </p>
  
  <p>And is there a way to wrap the call to GetStringFromUrl(url,callback) in the task itself (i.e. the call itself would run inside the task instead of synchronously)</p>