Application.Exit() doesn't work if app doesn't have any windows open
See original GitHub issueDescribe the bug
While trying to implement single instance redirection, I noticed that the Exit()
API doesn’t work unless the app has windows open. In the case of redirecting activation, after redirecting the activation, the second instance needs to be closed (without ever showing any windows). But calling Exit()
doesn’t do anything, the process stays running…
Steps to reproduce the bug
Steps to reproduce the behavior:
- Create a new WinUI 3 Desktop app, and in OnLaunched, update it to the following (exits itself after 6 seconds and never shows window)…
- Launch the app
- Open Task Manager, and notice that the process is still running (under background processes) after 6 seconds and never exits
Expected behavior
App should exit. The Exit()
API works if there’s an open activated window when it’s called, but doesn’t work when there’s no open window.
Version Info
NuGet package version: [WinUI 3 - Windows App SDK 1.0.0-preview1
Windows app type:
UWP | Win32 |
---|---|
Yes |
Windows version | Saw the problem? |
---|---|
Insider Build (xxxxx) | Yes |
May 2021 Update (19043) | |
October 2020 Update (19042) | |
May 2020 Update (19041) | |
November 2019 Update (18363) | |
May 2019 Update (18362) | |
October 2018 Update (17763) | |
April 2018 Update (17134) | |
Fall Creators Update (16299) | |
Creators Update (15063) |
Device form factor | Saw the problem? |
---|---|
Desktop | Yes |
Xbox | |
Surface Hub | |
IoT |
Additional context
Workaround is to use Process.GetCurrentProcess().Kill()
.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:11 (4 by maintainers)
Top Results From Across the Web
c# - Application.Exit() not working
Application.Exit is the "nice way" of shutting down a program. Outstanding windows messages are processed and only then are all windows closed.
Read more >Application.Exit Method (System.Windows.Forms)
Exit(). Informs all message pumps that they must terminate, and then closes all application windows after the messages have been processed.
Read more >[RESOLVED] I have a problem with Application.Exit() and ...
Hi, Working recently with a mondal form, I learned I have to Dispose the mondal form when the application closes.
Read more >app | Electron
Emitted when all windows have been closed and the application will quit. Calling event. ... Emitted when the app is no longer active...
Read more >Why Does Closing Windows on a Mac not Quit the Application?
https://macmost.com/e-2856 When switching from Windows to Mac many people wonder why Mac apps don't quit when you click the red close button ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
thanks @DJRM2021 . i double checked. My fix did make it in stable 1.3 release. 🎉🎉 (it wasn’t in experimental release but I suppose they picked up more commits later for stable branch and this is how it got in ). I have correctly added the milestone and will close the bug.
Thanks for posting this error. I found the problem and fixed it internally. Should come up in some future release. This bug will close automatically with that.