diff --git a/LightlessSync/Utils/TaskRegistry.cs b/LightlessSync/Utils/TaskRegistry.cs index 90b6fcf..7104548 100644 --- a/LightlessSync/Utils/TaskRegistry.cs +++ b/LightlessSync/Utils/TaskRegistry.cs @@ -31,34 +31,26 @@ public sealed class TaskRegistry where HandleType : notnull private Task GetOrStartInternal(HandleType handle, Func taskFactory) { - while (true) + Lazy entry = _activeTasks.GetOrAdd(handle, _ => CreateEntry(handle, taskFactory)); + Task task = entry.Value; + if (task.IsCompleted) { - Lazy entry = _activeTasks.GetOrAdd(handle, _ => CreateEntry(handle, taskFactory)); - Task task = entry.Value; - - if (!task.IsCompleted) - { - return task; - } - _activeTasks.TryRemove(new KeyValuePair>(handle, entry)); } + + return task; } private Task GetOrStartInternal(HandleType handle, Func> taskFactory) { - while (true) + Lazy entry = _activeTasks.GetOrAdd(handle, _ => CreateEntry(handle, taskFactory)); + Task task = entry.Value; + if (task.IsCompleted) { - Lazy entry = _activeTasks.GetOrAdd(handle, _ => CreateEntry(handle, taskFactory)); - Task task = entry.Value; - - if (!task.IsCompleted) - { - return (Task)task; - } - _activeTasks.TryRemove(new KeyValuePair>(handle, entry)); } + + return (Task)task; } private Lazy CreateEntry(HandleType handle, Func taskFactory)