title: Why is HttpContext.Current null after await?
body: <p>I have the following test WebAPI code, I don't use WebAPI in production but I made this because of a discussion I had on this question: <a href="https://stackoverflow.com/a/18367483/1981387">WebAPI Async question</a></p>
  
  <p>Anyways, here's the offending WebAPI method:</p>
  
  <pre><code>public async Task&lt;string&gt; Get(int id)
  {
      var x = HttpContext.Current;
      if (x == null)
      {
          // not thrown
          throw new ArgumentException("HttpContext.Current is null");
      }
  
      await Task.Run(() =&gt; { Task.Delay(500); id = 3; });
  
      x = HttpContext.Current;
      if (x == null)
      {
          // thrown
          throw new ArgumentException("HttpContext.Current is null");
      }
  
      return "value";
  }
  </code></pre>
  
  <p>I had hereto believed that the second exception is expected because when the <code>await</code> completes, it will likely be on a different thread where <code>HttpContext.Current</code> as a thread-static variable will no longer resolve to the appropriate value. Now, based on the synchronization context, it could actually be forced to go back to the same thread after the await but I'm not doing anything fancy in my test. This is just a plain, naive use of <code>await</code>.</p>
  
  <p>In comments in another question I was told that <code>HttpContext.Current</code> should resolve after an await. There's even another comment on this question indicating the same. So what's true? Should it resolve? I think no, but I want an authoritative answer on this because <code>async</code> and <code>await</code> is new enough that I can't find anything definitive.</p>
  
  <p>TL;DR: Is <code>HttpContext.Current</code> potentially <code>null</code> after an <code>await</code>?</p>