From ee59ded32f70c9ea90572d868e018bcb1a0d07fc Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Thu, 1 Feb 2024 15:35:40 +0200 Subject: [PATCH 1/2] perf(samplesapp): Make sure RefreshContainerPage timers are stopped --- .../RefreshContainerOnImagePage.xaml.cs | 10 ++++------ .../RefreshContainerTests/RefreshContainerPage.xaml.cs | 10 ++++------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/RefreshContainerTests/RefreshContainerOnImagePage.xaml.cs b/src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/RefreshContainerTests/RefreshContainerOnImagePage.xaml.cs index 75c54f1f6476..3af4de226688 100644 --- a/src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/RefreshContainerTests/RefreshContainerOnImagePage.xaml.cs +++ b/src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/RefreshContainerTests/RefreshContainerOnImagePage.xaml.cs @@ -40,7 +40,7 @@ public RefreshContainerOnImagePage() { this.InitializeComponent(); this.Loaded += OnMainPageLoaded; - + this.Unloaded += OnMainPageUnloaded; timer.Interval = new TimeSpan(0, 0, 0, 0, 800); timer.Tick += Timer_Tick; } @@ -50,11 +50,9 @@ public RefreshContainerOnImagePage() private bool delayRefresh = true; private int refreshCount = 0; - protected -#if HAS_UNO - internal -#endif - override void OnNavigatedFrom(NavigationEventArgs e) + // Uno specific: Unlike WinUI, we unsubscribe on Unloaded because we don't get OnNavigatedFrom. + // See point #2 in https://github.com/unoplatform/uno/issues/15059#issuecomment-1891551501 + private void OnMainPageUnloaded(object sender, RoutedEventArgs e) { base.OnNavigatedFrom(e); timer.Stop(); diff --git a/src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/RefreshContainerTests/RefreshContainerPage.xaml.cs b/src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/RefreshContainerTests/RefreshContainerPage.xaml.cs index 93eaacae1e32..805d7102e682 100644 --- a/src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/RefreshContainerTests/RefreshContainerPage.xaml.cs +++ b/src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/RefreshContainerTests/RefreshContainerPage.xaml.cs @@ -60,6 +60,7 @@ public RefreshContainerPage() { this.InitializeComponent(); this.Loaded += OnMainPageLoaded; + this.Unloaded += OnMainPageUnloaded; containerTimer.Interval = new TimeSpan(0, 0, 0, 5, 0); containerTimer.Tick += containerTimer_Tick; @@ -68,13 +69,10 @@ public RefreshContainerPage() LogController.InitializeLogging(); } - protected -#if HAS_UNO - internal -#endif - override void OnNavigatedFrom(NavigationEventArgs e) + // Uno specific: Unlike WinUI, we unsubscribe on Unloaded because we don't get OnNavigatedFrom. + // See point #2 in https://github.com/unoplatform/uno/issues/15059#issuecomment-1891551501 + private void OnMainPageUnloaded(object sender, RoutedEventArgs e) { - base.OnNavigatedFrom(e); containerTimer.Stop(); visualizerTimer.Stop(); } From 085548de7c5ae61de0cf9eda8bbcc94381cf76b4 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Thu, 1 Feb 2024 19:32:37 +0200 Subject: [PATCH 2/2] chore: Fix build error --- .../RefreshContainerTests/RefreshContainerOnImagePage.xaml.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/RefreshContainerTests/RefreshContainerOnImagePage.xaml.cs b/src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/RefreshContainerTests/RefreshContainerOnImagePage.xaml.cs index 3af4de226688..b87f2b52bbbe 100644 --- a/src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/RefreshContainerTests/RefreshContainerOnImagePage.xaml.cs +++ b/src/SamplesApp/UITests.Shared/Microsoft_UI_Xaml_Controls/RefreshContainerTests/RefreshContainerOnImagePage.xaml.cs @@ -54,7 +54,6 @@ public RefreshContainerOnImagePage() // See point #2 in https://github.com/unoplatform/uno/issues/15059#issuecomment-1891551501 private void OnMainPageUnloaded(object sender, RoutedEventArgs e) { - base.OnNavigatedFrom(e); timer.Stop(); }