Does executions of methodX()
in those two snippets are different ?
SemaphoreSlim _locker
.Wait()
& WaitAsync()
is just as example of same method having sync and async version.
答:
SemaphoreSlim _locker = new SemaphoreSlim(1);
async Task methodX()
{
_locker.Wait();
// .. rest of the code
}
B:
SemaphoreSlim _locker = new SemaphoreSlim(1);
async Task methodX()
{
await _locker.WaitAsync();
// .. rest of the code
}