title: ASP.NET HttpContext.Current inside Task.Run
body: <p>I have a following code example that is used in ASP.NET MVC application.
  The purpose of this code is to create "fire and forget" request for queuing some long running operation.</p>
  
  <pre><code>public JsonResult SomeAction() {
     HttpContext ctx = HttpContext.Current;            
  
     Task.Run(() =&gt; {
         HttpContext.Current = ctx;
         //Other long running code here.
     });
  
     return Json("{ 'status': 'Work Queued' }");
  }
  </code></pre>
  
  <p>I know this is not a good way for handling HttpContext.Current in asynchronous code, but currently our implementation not allows us to do something else.
  I would like to understand how much this code is dangerous...  </p>
  
  <p><strong>The question:</strong> Is it theoretically possible that setting the HttpContext inside Task.Run, will set the context to totally another request?  </p>
  
  <p>I think yes, but I'm not sure. How I understand it:
  Request1 is handled with Thread1 from thread pool, then while Thread1 is handling absolutelly another request (Request2), the code inside Task.Run will set context from Request1 to Request2.</p>
  
  <p>Maybe I am wrong, but my knowledge of ASP.NET internals not allows me to understand it correctly.</p>
  
  <p>Thanks!</p>