using Microsoft.UI.Xaml; namespace XFEWarframe.Desktop.Editing; /// UI-thread polling with one request at a time; leaving a page invalidates in-flight results. public sealed class EditorChangeMonitor { private readonly DispatcherTimer timer = new() { Interval = TimeSpan.FromSeconds(3) }; private readonly Func check; private bool checking; public bool Active { get; private set; } public int Generation { get; private set; } public EditorChangeMonitor(Func 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; } } }