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; }
}
}
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; }
}
}