XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEWarframe

【WinUI】基于Warframe游戏本体的公开服务器以及安装器

公开
关注 0 Fork 0 Star 0
UTF-8
using Microsoft.UI.Xaml;

namespace XFEWarframe.Desktop.Editing;

/// <summary>UI-thread polling with one request at a time; leaving a page invalidates in-flight results.</summary>
public sealed class EditorChangeMonitor
{
    private readonly DispatcherTimer timer = new() { Interval = TimeSpan.FromSeconds(3) };
    private readonly Func<Task> check;
    private bool checking;
    public bool Active { get; private set; }
    public int Generation { get; private set; }
    public EditorChangeMonitor(Func<Task> check)
    {
        this.check = check;
        timer.Tick += async (_, _) => await CheckAsync();
    }
    public void Start() { Stop(); Active = true; timer.Start(); }
    public void Stop() { timer.Stop(); Active = false; Generation++; }
    public async Task CheckAsync()
    {
        if (!Active || checking) return;
        checking = true;
        try { await check(); }
        finally { checking = false; }
    }
}