title: SignalR - How to perform async Task in hub?
body: <p>I am trying to create a SignalR application using the C# 5 async/await features, but whenever the code is run, it will throw an System.InvalidOperationException. Here is the simplest code to reproduce the problem.</p>
  
  <pre><code>public class SampleHub : Hub
  {
      public Task&lt;string&gt; GetGoogle()
      {
          var http = new WebClient();
          return http.DownloadStringTaskAsync("http://www.google.com");
      }
  }
  </code></pre>
  
  <p>Exception details:</p>
  
  <blockquote>
    <p>An asynchronous operation cannot be started at this time. Asynchronous operations may only be started within an asynchronous handler or module or during certain events in the Page lifecycle. If this exception occurred while executing a Page, ensure that the Page is marked &lt;%@ Page Async=\"true\" %>.</p>
  </blockquote>
  
  <p>Stack trace:</p>
  
  <pre><code>at System.Web.AspNetSynchronizationContext.OperationStarted()
  at System.Net.WebClient.DownloadStringAsync(Uri address, Object userToken)
  at System.Net.WebClient.DownloadStringTaskAsync(Uri address)
  at System.Net.WebClient.DownloadStringTaskAsync(String address)
  </code></pre>
  
  <p>On the client side, the Javascript looks like this.</p>
  
  <pre><code>$.connection.hub.start().done(function () {
      $('#google').click(function () {
          var google = sample.server.getGoogle();
          console.log(google);
      });
  });
  </code></pre>
  
  <p>What did I do wrong? Are there any workarounds? I am really keen to stick to the async/await patterns in C# if possible at all.</p>