mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
47 lines
1 KiB
C#
47 lines
1 KiB
C#
#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();
|
|
}
|
|
}
|
|
}
|
|
}
|