Skip to main content
1 of 3
user851220
  • 1.7k
  • 2
  • 10
  • 7

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

https://blog.cdemi.io/async-waiting-inside-c-sharp-locks/

Relevant code extract:

static SemaphoreSlim semaphoreSlim = new SemaphoreSlim(1, 1); ... await semaphoreSlim.WaitAsync(); try { await Task.Delay(1000); } finally { semaphoreSlim.Release(); } 
user851220
  • 1.7k
  • 2
  • 10
  • 7