From 0f022649a54d50ccd956b8ee3c9cb6dea68c0645 Mon Sep 17 00:00:00 2001 From: Michael Brunner Date: Tue, 22 Dec 2020 11:49:32 +0100 Subject: [PATCH] Fix for jobs still considered running --- AsyncScheduler/Scheduler.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/AsyncScheduler/Scheduler.cs b/AsyncScheduler/Scheduler.cs index 5672f68..7da30fb 100644 --- a/AsyncScheduler/Scheduler.cs +++ b/AsyncScheduler/Scheduler.cs @@ -388,7 +388,17 @@ private async void ResolveTaskEnd(string jobKey, Task task) } finally { - _runningJobs.TryRemove(jobKey, out _); + bool removed; + do + { + removed = _runningJobs.TryRemove(jobKey, out _); + if (!removed) + { + _logger.LogWarning("Unable to remove running job from ConcurrentDictionary: {jobKey} ... Retry...", jobKey); + await Task.Delay(TimeSpan.FromMilliseconds(50)); + } + } while (removed == false); + if (task is IDisposable disposable) { disposable.Dispose();