diff --git a/src/PlanViewer.App/Controls/QuerySessionControl.axaml.cs b/src/PlanViewer.App/Controls/QuerySessionControl.axaml.cs index 76f6534..23ee6f6 100644 --- a/src/PlanViewer.App/Controls/QuerySessionControl.axaml.cs +++ b/src/PlanViewer.App/Controls/QuerySessionControl.axaml.cs @@ -319,10 +319,13 @@ private string GetTextFromCursor() return text[batchStart..batchEnd].Trim(); } + private void SetStatus(string text, bool autoClear = true) { _statusClearCts?.Cancel(); _statusClearCts?.Dispose(); + _statusClearCts = null; // ← prevent stale reference to a disposed CTS + StatusText.Text = text; if (autoClear && !string.IsNullOrEmpty(text)) @@ -331,12 +334,18 @@ private void SetStatus(string text, bool autoClear = true) var token = _statusClearCts.Token; _ = Task.Delay(3000, token).ContinueWith(_ => { - Avalonia.Threading.Dispatcher.UIThread.Post(() => StatusText.Text = ""); + Avalonia.Threading.Dispatcher.UIThread.Post(() => + { + StatusText.Text = ""; + _statusClearCts = null; // ← also clear after natural expiry + }); }, TaskContinuationOptions.OnlyOnRanToCompletion); + } } - private async void Connect_Click(object? sender, RoutedEventArgs e) + + private async void Connect_Click(object? sender, RoutedEventArgs e) { await ShowConnectionDialogAsync(); }