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