我试图找出是什么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'方法之间的区别一样:一个区块,另一个区块产生线程。 –