XAML-Map-Control/MapControl/WinUI/Timer.WinUI.cs
2024-02-03 21:01:53 +01:00

34 lines
839 B
C#

// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// Copyright © 2024 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using Microsoft.UI.Dispatching;
using Microsoft.UI.Xaml;
using System;
namespace MapControl
{
internal static class Timer
{
public static DispatcherQueueTimer CreateTimer(this DependencyObject obj, TimeSpan interval)
{
var timer = obj.DispatcherQueue.CreateTimer();
timer.Interval = interval;
return timer;
}
public static void Run(this DispatcherQueueTimer timer, bool restart = false)
{
if (restart)
{
timer.Stop();
}
if (!timer.IsRunning)
{
timer.Start();
}
}
}
}