From 2f6f7ee4eb94893f7bf4a94b9481a15c19f428ee Mon Sep 17 00:00:00 2001 From: ClemensFischer Date: Sat, 25 Oct 2025 20:29:25 +0200 Subject: [PATCH] Remove DispatcherTimerExtensions --- .../Shared/DispatcherTimerExtensions.cs | 46 ------------------- MapControl/Shared/MapImageLayer.cs | 19 ++++++-- MapControl/Shared/MapTilePyramidLayer.cs | 17 +++++-- 3 files changed, 29 insertions(+), 53 deletions(-) delete mode 100644 MapControl/Shared/DispatcherTimerExtensions.cs diff --git a/MapControl/Shared/DispatcherTimerExtensions.cs b/MapControl/Shared/DispatcherTimerExtensions.cs deleted file mode 100644 index a87cd339..00000000 --- a/MapControl/Shared/DispatcherTimerExtensions.cs +++ /dev/null @@ -1,46 +0,0 @@ -#if WPF -using System.Windows; -using System.Windows.Threading; -#elif UWP -using Windows.UI.Xaml; -#elif WINUI -global using DispatcherTimer = Microsoft.UI.Dispatching.DispatcherQueueTimer; -using Microsoft.UI.Xaml; -#elif AVALONIA -using DependencyObject = Avalonia.AvaloniaObject; -using Avalonia.Threading; -#endif -using System; - -namespace MapControl -{ - internal static class DispatcherTimerExtensions - { - public static DispatcherTimer CreateTimer(this DependencyObject obj, TimeSpan interval) - { -#if WINUI - var timer = obj.DispatcherQueue.CreateTimer(); -#else - var timer = new DispatcherTimer(); -#endif - timer.Interval = interval; - return timer; - } - - public static void Run(this DispatcherTimer timer, bool restart = false) - { - if (restart) - { - timer.Stop(); - } -#if WINUI - if (!timer.IsRunning) -#else - if (!timer.IsEnabled) -#endif - { - timer.Start(); - } - } - } -} diff --git a/MapControl/Shared/MapImageLayer.cs b/MapControl/Shared/MapImageLayer.cs index 5d5b1d0b..8477a03b 100644 --- a/MapControl/Shared/MapImageLayer.cs +++ b/MapControl/Shared/MapImageLayer.cs @@ -62,7 +62,7 @@ namespace MapControl loadingProgress = new Progress(p => SetValue(LoadingProgressProperty, p)); - updateTimer = this.CreateTimer(UpdateInterval); + updateTimer = new DispatcherTimer { Interval = UpdateInterval }; updateTimer.Tick += async (s, e) => await UpdateImageAsync(); } @@ -164,7 +164,15 @@ namespace MapControl } else { - updateTimer.Run(!UpdateWhileViewportChanging); + if (!UpdateWhileViewportChanging) + { + updateTimer.Stop(); + } + + if (!updateTimer.IsEnabled) + { + updateTimer.Start(); + } } } @@ -174,9 +182,12 @@ namespace MapControl { if (updateInProgress) { - // Update image on next tick, start timer if not running. + // Update image on next timer tick. // - updateTimer.Run(); + if (!updateTimer.IsEnabled) + { + updateTimer.Start(); + } } else { diff --git a/MapControl/Shared/MapTilePyramidLayer.cs b/MapControl/Shared/MapTilePyramidLayer.cs index 5cd4a94f..b1c9790d 100644 --- a/MapControl/Shared/MapTilePyramidLayer.cs +++ b/MapControl/Shared/MapTilePyramidLayer.cs @@ -68,7 +68,7 @@ namespace MapControl loadingProgress = new Progress(p => SetValue(LoadingProgressProperty, p)); - updateTimer = this.CreateTimer(UpdateInterval); + updateTimer = new DispatcherTimer { Interval = UpdateInterval }; updateTimer.Tick += (s, e) => Update(false); MapPanel.SetRenderTransform(this, new MatrixTransform()); @@ -185,7 +185,10 @@ namespace MapControl parentMap.ViewportChanged += OnViewportChanged; } - updateTimer.Run(); + if (!updateTimer.IsEnabled) + { + updateTimer.Start(); + } } } @@ -229,7 +232,15 @@ namespace MapControl { SetRenderTransform(); - updateTimer.Run(!UpdateWhileViewportChanging); + if (!UpdateWhileViewportChanging) + { + updateTimer.Stop(); + } + + if (!updateTimer.IsEnabled) + { + updateTimer.Start(); + } } } }