Skip to content

Instantly share code, notes, and snippets.

@aetos382 aetos382/aspeap.cs
Last active Sep 16, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.