参考网址: https://www.cnblogs.com/Alicia-meng/p/13330640.html
private static readonly SemaphoreSlim _mutex = new SemaphoreSlim(1);
static int _value;
public async static Task DelayAndIncrementAsync()
{
await _mutex.WaitAsync();
try
{
var oldValue = _value;
await Task.Delay(TimeSpan.FromSeconds(oldValue));
Console.WriteLine(_value);
_value = oldValue + 1;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
_mutex.Release();
}
}
原文:https://www.cnblogs.com/bruce1992/p/15128173.html