Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@aetos382
Last active September 16, 2015 03:44
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 aetos382/89f39a0f455568ccf105 to your computer and use it in GitHub Desktop.
Save aetos382/89f39a0f455568ccf105 to your computer and use it in GitHub Desktop.
public async Task<ActionResult> Index()
{
// ここはリクエスト スレッドで実行される
Debug.WriteLine("Index : {0}", Thread.CurrentThread.ManagedThreadId);
ThreadPool.QueueUserWorkItem(this.WorkerThread);
var client = new WebClient();
client.Encoding = Encoding.UTF8;
client.DownloadStringCompleted += this.OnDownloadStringCompleted;
client.DownloadStringAsync(new Uri("http://tech.blog.aerie.jp"));
return View();
}
private void WorkerThread(object state)
{
// ここはワーカー スレッドで実行されるので、HttpContext.Current は null
Debug.WriteLine("WorkerThreac : {0}", Thread.CurrentThread.ManagedThreadId);
Debug.WriteLine("HttpContext {0}= null", new[] { System.Web.HttpContext.Current == null ? "=" : "!" });
}
private void OnDownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
// ここはワーカー スレッドで実行されるが、HttpContext.Current は null ではない
Debug.WriteLine("OnGetResponseCompleted : {0}", Thread.CurrentThread.ManagedThreadId);
Debug.WriteLine("HttpContext {0}= null", new[] { System.Web.HttpContext.Current == null ? "=" : "!" });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment