diff --git a/Terminal.Gui/App/Timeout/TimedEvents.cs b/Terminal.Gui/App/Timeout/TimedEvents.cs
index 3e3b3a102..b77e0520d 100644
--- a/Terminal.Gui/App/Timeout/TimedEvents.cs
+++ b/Terminal.Gui/App/Timeout/TimedEvents.cs
@@ -133,33 +133,24 @@ public class TimedEvents : ITimedEvents
k -= 100;
}
- _timeouts.Add (NudgeToUniqueKey (k, time == TimeSpan.Zero), timeout);
+ _timeouts.Add (NudgeToUniqueKey (k), timeout);
Added?.Invoke (this, new (timeout, k));
}
}
///
- /// Finds the closest number to that is not present in .
- /// For immediate execution timeouts (decrementForImmediate=true), decrements to maintain FIFO order.
- /// For delayed timeouts, increments to maintain order.
+ /// Finds the closest number to that is not present in
+ /// (incrementally).
///
- /// The initial key to try
- /// If true, decrements on collision; otherwise increments
- /// A unique key
- private long NudgeToUniqueKey (long k, bool decrementForImmediate)
+ ///
+ ///
+ private long NudgeToUniqueKey (long k)
{
lock (_timeoutsLockToken)
{
while (_timeouts.ContainsKey (k))
{
- if (decrementForImmediate)
- {
- k--;
- }
- else
- {
- k++;
- }
+ k++;
}
}
@@ -194,8 +185,7 @@ public class TimedEvents : ITimedEvents
{
lock (_timeoutsLockToken)
{
- // When re-adding non-executed timeouts, increment on collision to maintain original order
- _timeouts.Add (NudgeToUniqueKey (k, decrementForImmediate: false), timeout);
+ _timeouts.Add (NudgeToUniqueKey (k), timeout);
}
}
}
diff --git a/Tests/UnitTests/Application/MainLoopTests.cs b/Tests/UnitTests/Application/MainLoopTests.cs
index 1ca9ae7e3..f2caa1069 100644
--- a/Tests/UnitTests/Application/MainLoopTests.cs
+++ b/Tests/UnitTests/Application/MainLoopTests.cs
@@ -661,35 +661,6 @@ public class MainLoopTests
Application.Shutdown ();
}
-
- [Fact]
- public void TimeSpanZero_Timeouts_Execute_In_FIFO_Order ()
- {
- var ml = new MainLoop (new FakeMainLoop ());
- var executionOrder = new List ();
-
- // Add multiple timeouts with TimeSpan.Zero in quick succession
- // They should execute in the order they were added (FIFO)
- for (int i = 0; i < 10; i++)
- {
- int capturedI = i;
- ml.TimedEvents.Add (TimeSpan.Zero, () =>
- {
- executionOrder.Add (capturedI);
- return false; // Don't repeat
- });
- }
-
- // Run one iteration to execute all pending timeouts
- ml.RunIteration ();
-
- // Verify they executed in FIFO order (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
- Assert.Equal (10, executionOrder.Count);
- for (int i = 0; i < 10; i++)
- {
- Assert.Equal (i, executionOrder [i]);
- }
- }
[Fact]
public void RemoveIdle_Function_NotCalled ()