Call async code in an Action in C# : <p>I'm calling a web service from some C# code. This code looks similar to this:</p>

<pre><code>using (var client = new HttpClient())
{
  var page = "http://en.wikipedia.org/";
  using (var response = await client.GetAsync(page))
  {
    using (var content = response.Content)
    {
      var result = await content.ReadAsStringAsync();
    }
  }
}
</code></pre>

<p>I want to execute this code within a utility method. From my understanding, an <a href="https://msdn.microsoft.com/en-us/library/018hxwa8(v=vs.110).aspx" rel="nofollow noreferrer">Action</a> delegate is suited for this. I attempted to do this using the following:</p>

<pre><code>Action action = delegate()
{
  using (var client = new HttpClient())
  {
    var page = "http://en.wikipedia.org/";
    using (var response = await client.GetAsync(page))
    {
      using (var content = response.Content)
      {
        var result = await content.ReadAsStringAsync();
      }
    }
  }
}
</code></pre>

<p>When I wrap my web service code in an <code>Action</code> delegate, I receive a compile-time error that says:</p>

<pre><code>The 'await' operator can only be used within an async anonymous method. Consider marking this anonymous method with the 'async' modifier.
</code></pre>

<p>My question is, how do I call async code in an Action? It looks like I can't. If I can't is there another way that I can pass a block of code to a utility method for execution? What does that look like?</p>

<p>Thank you!</p>
