From e9712d1730b06e22e246f424ad8881eeddbeb410 Mon Sep 17 00:00:00 2001 From: bluepilledgreat <97983689+bluepilledgreat@users.noreply.github.com> Date: Tue, 29 Oct 2024 20:44:14 +0000 Subject: [PATCH] stop countdown on unload --- .../Settings/Pages/FastFlagEditorWarningPage.xaml | 1 + .../Settings/Pages/FastFlagEditorWarningPage.xaml.cs | 5 +++++ .../ViewModels/Settings/FastFlagEditorWarningViewModel.cs | 8 +++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Bloxstrap/UI/Elements/Settings/Pages/FastFlagEditorWarningPage.xaml b/Bloxstrap/UI/Elements/Settings/Pages/FastFlagEditorWarningPage.xaml index 9a2b938..55b0d71 100644 --- a/Bloxstrap/UI/Elements/Settings/Pages/FastFlagEditorWarningPage.xaml +++ b/Bloxstrap/UI/Elements/Settings/Pages/FastFlagEditorWarningPage.xaml @@ -10,6 +10,7 @@ d:DesignHeight="450" d:DesignWidth="800" Scrollable="True" Loaded="Page_Loaded" + Unloaded="Page_Unloaded" Title="FastFlagEditorWarningPage"> diff --git a/Bloxstrap/UI/Elements/Settings/Pages/FastFlagEditorWarningPage.xaml.cs b/Bloxstrap/UI/Elements/Settings/Pages/FastFlagEditorWarningPage.xaml.cs index 8a8d723..6f35278 100644 --- a/Bloxstrap/UI/Elements/Settings/Pages/FastFlagEditorWarningPage.xaml.cs +++ b/Bloxstrap/UI/Elements/Settings/Pages/FastFlagEditorWarningPage.xaml.cs @@ -31,5 +31,10 @@ namespace Bloxstrap.UI.Elements.Settings.Pages ((FastFlagEditorWarningViewModel)DataContext).StartCountdown(); } + + private void Page_Unloaded(object sender, RoutedEventArgs e) + { + ((FastFlagEditorWarningViewModel)DataContext).StopCountdown(); + } } } diff --git a/Bloxstrap/UI/ViewModels/Settings/FastFlagEditorWarningViewModel.cs b/Bloxstrap/UI/ViewModels/Settings/FastFlagEditorWarningViewModel.cs index 08a18fe..957f62b 100644 --- a/Bloxstrap/UI/ViewModels/Settings/FastFlagEditorWarningViewModel.cs +++ b/Bloxstrap/UI/ViewModels/Settings/FastFlagEditorWarningViewModel.cs @@ -28,9 +28,15 @@ namespace Bloxstrap.UI.ViewModels.Settings _page = page; } - public void StartCountdown() + public void StopCountdown() { _cancellationTokenSource?.Cancel(); + _cancellationTokenSource = null; + } + + public void StartCountdown() + { + StopCountdown(); _cancellationTokenSource = new CancellationTokenSource(); DoCountdown(_cancellationTokenSource.Token);