只是想確保我得到這個正確的,因爲我看到一些奇怪的行爲根據我的結果。C# - 等待和異步
public async Task<System.Net.HttpStatusCode> GetJson(Stream inputJson)
{
......
.....
...
var query1 = from xxx in new xxx()
where xxx.id == myID
select xxx;
var results1 = await query1.FindAsync();
var query2 = from yyy in new yyy()
where yyy.id == myID
select yyy;
var results2 = await query2.FindAsync();
...
....
.....
return System.Net.HttpStatusCode.OK;
}
將query2
執行後,才query1
執行完畢:
如下我定義了一個異步方法?還是並行?
'query2'將在'query1'產生結果後執行。 – ThePerplexedOne
@Polis:一個好的心理捷徑是:'await'意思是「異步等待」,所以它*等待。它只是等待而不是阻塞。 –