diff --git a/src/PlanViewer.App/Controls/QuerySessionControl.axaml.cs b/src/PlanViewer.App/Controls/QuerySessionControl.axaml.cs index 76f6534..fc29d39 100644 --- a/src/PlanViewer.App/Controls/QuerySessionControl.axaml.cs +++ b/src/PlanViewer.App/Controls/QuerySessionControl.axaml.cs @@ -319,17 +319,21 @@ private string GetTextFromCursor() return text[batchStart..batchEnd].Trim(); } + private void SetStatus(string text, bool autoClear = true) { - _statusClearCts?.Cancel(); - _statusClearCts?.Dispose(); + var old = _statusClearCts; + _statusClearCts = null; + old?.Cancel(); + old?.Dispose(); + StatusText.Text = text; if (autoClear && !string.IsNullOrEmpty(text)) { - _statusClearCts = new CancellationTokenSource(); - var token = _statusClearCts.Token; - _ = Task.Delay(3000, token).ContinueWith(_ => + var cts = new CancellationTokenSource(); + _statusClearCts = cts; + _ = Task.Delay(3000, cts.Token).ContinueWith(_ => { Avalonia.Threading.Dispatcher.UIThread.Post(() => StatusText.Text = ""); }, TaskContinuationOptions.OnlyOnRanToCompletion);