title: MVC AsyncController Blocking
body: <p>So I've been following along with Steven Sanderson's <a href="http://channel9.msdn.com/Events/TechDays/Techdays-2012-the-Netherlands/2287" rel="nofollow">TechDays Talk</a> on SignalR and ASP.NET Async. I've run into a problem with the following actions</p>
  
  <pre><code>public class SomeController : AsyncController
  {
      static TaskCompletionSource&lt;String&gt; _nextMessage
          = new TaskCompletionSource&lt;string&gt;();
  
      [HttpPost]
      public ActionResult PostMessage(string message)
      {            
          _nextMessage = new TaskCompletionSource&lt;string&gt;();
          oldNextMessage.SetResult(message);
          return Content("success");
      }
  
      public async void GetMessages()
      {
          Response.ContentType = "text/event-stream";
          while (true)
          {
              var message = await _nextMessage.Task;
              Response.Write("data: " + message + "\n\n");
              Response.Flush();
          }
  
      }
  }
  </code></pre>
  
  <p>GetMessages seems to be blocking when it is first called, but once it times out, it starts working as expected.</p>
  
  <p>So I load up my javascript which posts and runs GetMessages. On the first call to GetMessages, it hangs (as expected) at</p>
  
  <pre><code>await _nextMessage.Task;
  </code></pre>
  
  <p>but it won't let me make a call to PostMessage from any where (including other instances of the browser) This is on my dev machine, so it may be a thread issue, but I thought the whole purpose of this was to allow threads to work on multiple things. And that's besides the point that after it times out the first time, it starts to work as expected, where I can post, and get responses immediately. But if I refresh the page, I get the same problem. Any ideas on how to fix this? I'm using Eventsource by the way, but the same problem occurs when I'm doing long polling e.g.</p>
  
  <pre><code>    public async Task&lt;string&gt; GetNextMessage()
      {
  
          return await _nextMessage.Task;
      }
  </code></pre>
  
  <p>with a javascript loop function calling GetNextMessage()</p>