Lock and Async method in C#

This has been disallowed to stop deadlocks (i.e. developers hurting themselves). The best solution I’ve found is to use semaphores – See this post for details.

Relevant code extract:

static SemaphoreSlim semaphoreSlim = new SemaphoreSlim(1, 1);

...

await semaphoreSlim.WaitAsync();
try
{
    await Task.Delay(1000);
}
finally
{
    semaphoreSlim.Release();
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)