1
在Asp.Net网页按钮点击我有下面的代码任务和线程调度在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();
使用await意味着我必须使用异步页面处理程序吗?否则响应会在异步任务完成之前返回到浏览器。 – 2014-12-19 03:23:08
@SriHarshaVelicheti我相信如此。看看[这个](http://www.hanselman.com/blog/TheMagicOfUsingAsynchronousMethodsInASPNET45PlusAnImportantGotcha.aspx) – i3arnon 2014-12-19 03:26:08