Compare commits

...

2 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
d0ce5f1cb8 fix: handle Win32Exception(1400) in PowerLauncher after fast user switch
When a Windows fast user switch occurs, the WPF Dispatcher's internal
message-only window handle can become invalid upon session restoration.
This causes GetMessage() to return -1 (ERROR_INVALID_WINDOW_HANDLE = 1400),
resulting in an unhandled Win32Exception that crashed PowerLauncher.

The fix wraps application.Run() in a try-catch for Win32Exception with
NativeErrorCode 1400, logging the event and exiting gracefully instead
of showing a crash dialog. The PowerToys runner will then restart
PowerLauncher automatically.

Fixes: crash after swapping between users (fast user switching)

Agent-Logs-Url: https://github.com/microsoft/PowerToys/sessions/6ad8bf4b-7b0b-458b-80c7-e327b9031efd

Co-authored-by: MuyuanMS <116717757+MuyuanMS@users.noreply.github.com>
2026-04-29 09:07:33 +00:00
copilot-swe-agent[bot]
d1cc160a72 Initial plan 2026-04-29 08:50:25 +00:00

View File

@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
@@ -120,7 +121,18 @@ namespace PowerLauncher
});
}
application.Run();
try
{
application.Run();
}
catch (Win32Exception ex) when (ex.NativeErrorCode == 1400)
{
// ERROR_INVALID_WINDOW_HANDLE (1400) can be thrown by the WPF dispatcher
// after a fast user switch, when its internal message-only window handle
// becomes invalid upon session restoration. Exit gracefully so the
// PowerToys runner can restart PowerLauncher.
Log.Warn($"PowerToys Run exiting due to invalid window handle after user switch: {ex.Message}", typeof(App));
}
}
}