我試圖找出是什麼SemaphoreSlim使用等待和WaitAsync之間的差異,在這種情況下的使用:信號燈等待VS WaitAsync在異步方法
private SemaphoreSlim semaphore = new SemaphoreSlim(1);
public async Task<string> Get()
{
// What's the difference between using Wait and WaitAsync here?
this.semaphore.Wait(); // await this.semaphore.WaitAsync()
string result;
try {
result = this.GetStringAsync();
}
finally {
this.semaphore.Release();
}
return result;
}
與大多數其他'XXX'和'XXXAsync'方法之間的區別一樣:一個區塊,另一個區塊產生線程。 –