【发布时间】:2014-12-19 03:13:22
【问题描述】:
在 Asp.Net 网页按钮中单击我有以下代码
//Code is running on Asp.Net worker Thread
var httpClient = new HttpClient();
var task = httpClient.GetAsync("/someapiCall"); //Creates a new thread and executed on it
task.Wait();
现在当我调用 task.Wait 时工作线程会发生什么?
- 会处于挂起状态等待 httpClient 调用完成吗?
- 是否会返回到线程池并可以处理其他请求?
上面的代码和下面的代码有什么区别
var httpClient = new HttpClient();
var task = httpClient.GetAsync("/someapiCall"); //Creates a new thread and executed on it
ManualResetEvent mre = new ManualResetEvent(false);
task.ContinueWith((t) => { mre.Set(); });
mre.WaitOne();
【问题讨论】:
标签: c# asp.net .net multithreading task-parallel-library