Description
Summary
In unpackaged WinUI 3 (WindowsPackageType=None, NativeAOT / self-contained), closing the application via the caption close button (X), Alt+F4, or taskbar context menu destroys the window surface, but does not reliably terminate the host CLR process if background thread pool workers, async preload tasks, or WinRT synchronization contexts remain active.
In our testing, the process can remain running indefinitely in Task Manager as a background process holding ~180–220 MB RAM.
Root Cause
In FluentCleaner/App.xaml.cs:
MainWindow.Closed += (_, _) =>
{
var size = MainWindow.AppWindow.Size;
AppSettings.Instance.WindowWidth = size.Width;
AppSettings.Instance.WindowHeight = size.Height;
AppSettings.Instance.Save();
};In unpackaged desktop WinUI 3, Window.Closed does not automatically invoke Application.Exit(). Furthermore, when window customization or AppWindowTitleBar is active, the caption button close event routes through AppWindow.Closing before Window.Closed.
Proposed Fix
Wire both MainWindow.Closed and MainWindow.AppWindow.Closing to explicitly exit the application and runtime:
MainWindow.Closed += (_, _) =>
{
try
{
var size = MainWindow.AppWindow.Size;
AppSettings.Instance.WindowWidth = size.Width;
AppSettings.Instance.WindowHeight = size.Height;
AppSettings.Instance.Save();
}
catch { }
finally
{
Microsoft.UI.Xaml.Application.Current.Exit();
Environment.Exit(0);
}
};
MainWindow.AppWindow.Closing += (_, _) =>
{
try
{
var size = MainWindow.AppWindow.Size;
AppSettings.Instance.WindowWidth = size.Width;
AppSettings.Instance.WindowHeight = size.Height;
AppSettings.Instance.Save();
}
catch { }
finally
{
Microsoft.UI.Xaml.Application.Current.Exit();
Environment.Exit(0);
}
};Note on AppInfo.cs
For forks and community PRs migrating to 26.11.123: ensure any pre-release or duplicate declarations of public static bool IsEleven are consolidated to line 28 (which was canonically added in commit 83828a1) to prevent Roslyn CS0102 duplicate symbol errors during merge.
Activity