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

34 lines
834 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 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();
}
}
}
}