XAML-Map-Control/MapControl/WPF/Timer.WPF.cs

37 lines
817 B
C#
Raw Normal View History

2022-01-12 23:56:05 +01:00
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
2024-02-03 21:01:53 +01:00
// Copyright © 2024 Clemens Fischer
2022-01-12 23:56:05 +01:00
// Licensed under the Microsoft Public License (Ms-PL)
using System;
2024-05-20 23:24:34 +02:00
#if AVALONIA
using Avalonia.Threading;
#elif UWP
2022-01-12 23:56:05 +01:00
using Windows.UI.Xaml;
#else
using System.Windows.Threading;
#endif
namespace MapControl
{
internal static class Timer
{
2024-05-20 23:24:34 +02:00
public static DispatcherTimer CreateTimer(this object _, TimeSpan interval)
2022-01-12 23:56:05 +01:00
{
2024-05-20 23:24:34 +02:00
return new DispatcherTimer { Interval = interval };
2022-01-12 23:56:05 +01:00
}
public static void Run(this DispatcherTimer timer, bool restart = false)
{
if (restart)
{
timer.Stop();
}
if (!timer.IsEnabled)
{
timer.Start();
}
}
}
}