diff --git a/src/core/Akka.TestKit/TestScheduler.cs b/src/core/Akka.TestKit/TestScheduler.cs index 8a224a8a80f..4315cc815a1 100644 --- a/src/core/Akka.TestKit/TestScheduler.cs +++ b/src/core/Akka.TestKit/TestScheduler.cs @@ -88,10 +88,14 @@ private void InternalSchedule(TimeSpan? initialDelay, TimeSpan delay, ICanTell r { var scheduledTime = _now.Add(initialDelay ?? delay).UtcTicks; - if (!_scheduledWork.TryGetValue(scheduledTime, out var tickItems)) + ConcurrentQueue tickItems; + while (!_scheduledWork.TryGetValue(scheduledTime, out tickItems)) { tickItems = new ConcurrentQueue(); - _scheduledWork.TryAdd(scheduledTime, tickItems); + if (_scheduledWork.TryAdd(scheduledTime, tickItems)) + { + break; + } } var type = message == null ? ScheduledItem.ScheduledItemType.Action : ScheduledItem.ScheduledItemType.Message;