private void DoWork(object state) { if (Monitor.TryEnter(_lock)) { try { _logger.LogDebug($"Running DoWork iteration {_counter}"); _myService.DoWorkAsync().Wait(); _logger.LogDebug($"DoWork {_counter} finished, will start iteration {_counter + 1}"); } finally { _counter++; Monitor.Exit(_lock); } } else { _logger.LogDebug($"Iteration {_counter } of DoWork is still running"); } }