File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change 88using Microsoft . Windows . AppNotifications . Builder ;
99using Microsoft . Windows . BadgeNotifications ;
1010using System ;
11+ using System . Collections . Generic ;
1112using System . Diagnostics ;
1213using System . Linq ;
1314using Windows . ApplicationModel . Activation ;
@@ -60,6 +61,23 @@ protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs ar
6061 MainWindow . Closed += ( s , e ) =>
6162 {
6263 BadgeNotificationManager . Current . ClearBadge ( ) ;
64+
65+ // Close all remaining active windows to prevent resource disposal conflicts
66+ var activeWindows = new List < Window > ( WindowHelper . ActiveWindows ) ;
67+ foreach ( var window in activeWindows )
68+ {
69+ if ( window != s ) // Don't try to close the window that's already closing
70+ {
71+ try
72+ {
73+ window . Close ( ) ;
74+ }
75+ catch
76+ {
77+ // Ignore any exceptions during cleanup
78+ }
79+ }
80+ }
6381 } ;
6482 }
6583
Original file line number Diff line number Diff line change 33
44using Microsoft . UI . Xaml ;
55using Microsoft . UI . Xaml . Controls ;
6+ using WinUIGallery . Helpers ;
67using WinUIGallery . Pages ;
78
89namespace WinUIGallery . ControlPages ;
@@ -17,6 +18,7 @@ public CreateMultipleWindowsPage()
1718 private void createNewWindow_Click ( object sender , RoutedEventArgs e )
1819 {
1920 var newWindow = new MainWindow ( ) ;
21+ WindowHelper . TrackWindow ( newWindow ) ;
2022 newWindow . Activate ( ) ;
2123
2224 var targetPageType = typeof ( HomePage ) ;
You can’t perform that action at this time.
0 commit comments