Last active
September 16, 2015 03:44
-
-
Save aetos382/89f39a0f455568ccf105 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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