question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Application.Exit() doesn't work if app doesn't have any windows open

See original GitHub issue

Describe 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:

  1. Create a new WinUI 3 Desktop app, and in OnLaunched, update it to the following (exits itself after 6 seconds and never shows window)…

image

  1. Launch the app
  2. 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:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
pratikonecommented, Apr 20, 2023

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.

1reaction
pratikonecommented, Jan 20, 2023

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found