using Elwig.Helpers; using System; using System.Threading.Tasks; using System.Windows; namespace Elwig.Windows { public abstract class ContextWindow : Window { protected bool LockContext { get; set; } = false; private bool _renewPending = false; public ContextWindow() : base() { Loaded += OnLoaded; } public async Task HintContextChange() { _renewPending = true; if (LockContext) return; await RenewContext(); } protected async void OnLoaded(object? sender, RoutedEventArgs? evt) { using var ctx = new AppDbContext(); await OnRenewContext(ctx); } protected async Task RenewContext() { if (!_renewPending) return; using var ctx = new AppDbContext(); await OnRenewContext(ctx); _renewPending = false; } abstract protected Task OnRenewContext(AppDbContext ctx); } }