Skip to content

Instantly share code, notes, and snippets.

@neuecc
Created September 29, 2014 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neuecc/4ceaa5a4ca3f8e915b43 to your computer and use it in GitHub Desktop.
Save neuecc/4ceaa5a4ca3f8e915b43 to your computer and use it in GitHub Desktop.
AspNetSynchtonizationContext.cs
async Task Hoge()
{
Debug.WriteLine(System.Web.HttpContext.Current == null); // false
await Task.Delay(TimeSpan.FromMilliseconds(100)).ConfigureAwait(false); // キャプチャしない
Debug.WriteLine(System.Web.HttpContext.Current == null); // true
}
public async Task<ActionResult> Index()
{
Debug.WriteLine(System.Web.HttpContext.Current == null); // false
await Hoge(); // 生きてるHttpContextをキャプチャする
Debug.WriteLine(System.Web.HttpContext.Current == null); // false
return View();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment