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

36 lines
807 B
C#
Raw Normal View History

2022-01-12 23:56:05 +01:00
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
2025-01-01 18:57:55 +01:00
// Copyright © Clemens Fischer
2022-01-12 23:56:05 +01:00
// Licensed under the Microsoft Public License (Ms-PL)
using System;
2024-05-22 11:25:32 +02:00
#if WPF
2024-05-22 21:20:49 +02:00
using System.Windows;
2024-05-22 11:25:32 +02:00
using System.Windows.Threading;
2024-05-20 23:24:34 +02:00
#elif UWP
2022-01-12 23:56:05 +01:00
using Windows.UI.Xaml;
#endif
namespace MapControl
{
internal static class Timer
{
2024-05-22 21:20:49 +02:00
public static DispatcherTimer CreateTimer(this DependencyObject _, 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();
}
}
}
}