From 8f39af95799db67268a00e5b8ce9e5c025c4cc21 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Sun, 4 Aug 2024 15:40:54 -0700 Subject: [PATCH] fix: Fixes Timer.Pause not running continuation (#1893) --- Projects/Server/Timer/Timer.TimerWheel.cs | 12 ++++++++++-- Projects/Server/Timer/Timer.cs | 14 ++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Projects/Server/Timer/Timer.TimerWheel.cs b/Projects/Server/Timer/Timer.TimerWheel.cs index 1e6ee9e8d..bfff860ea 100644 --- a/Projects/Server/Timer/Timer.TimerWheel.cs +++ b/Projects/Server/Timer/Timer.TimerWheel.cs @@ -142,7 +142,7 @@ public partial class Timer // Stop the timer from running so that way if Start() is called in OnTick, the timer will be started. if (finished) { - timer.Stop(); + timer.InternalStop(); } var version = timer.Version; @@ -151,11 +151,19 @@ public partial class Timer prof?.Finish(); // If the timer has been altered (restarted, returned etc) then bail - if (finished || timer.Version != version) + if (timer.Version != version) { return; } + if (finished) + { + // Already stopped and detached, now run OnDetach + timer.OnDetach(); + timer.Version++; + return; + } + timer.Delay = timer.Interval; timer.Next = DateTime.UtcNow + timer.Interval; AddTimer(timer, (long)timer.Delay.TotalMilliseconds); diff --git a/Projects/Server/Timer/Timer.cs b/Projects/Server/Timer/Timer.cs index 3919db6a3..898393557 100644 --- a/Projects/Server/Timer/Timer.cs +++ b/Projects/Server/Timer/Timer.cs @@ -151,6 +151,16 @@ public partial class Timer return; } + InternalStop(); + + Detach(); + OnDetach(); + + Version++; + } + + private void InternalStop() + { Running = false; // We are the head on the timer ring @@ -165,15 +175,11 @@ public partial class Timer _executingRings[_ring] = _nextTimer; } - Detach(); - OnDetach(); - var prof = GetProfile(); if (prof != null) { prof.Stopped++; } - Version++; } protected virtual void OnTick()