Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exit or close an UWP app programmatically? (Windows 10)

Tags:

c#

windows-10

uwp

I need it for their own exit button. Tell me please? I try this: this.Close(); //or Exit dont work(

like image 594
AlexeySRG Avatar asked Sep 20 '15 09:09

AlexeySRG


People also ask

Is Microsoft killing UWP?

Microsoft continues to baby-step around the obvious, but it has officially deprecated the Universal Windows Platform (UWP) as it pushes the desktop-focused Windows App SDK (formerly called Project Reunion) and WinUI 3 as the future of Windows application development.

How do I find my UWP app?

If the file location is the WindowsApps folder in Program Files, or Windows 10 refuses to open the folder, then it is a UWP App, because Win32 apps are stored in their own folder in Program Files (x86) and 64bit applications are stored in their own folder in Program Files . . . Power to the Developer!

How do I fix UWP app not opening?

Please run Windows Store Apps troubleshooter from Settings app > Update & security > Troubleshoot. See if it helps you. Hope this helps!


1 Answers

You can use the CoreApplication class. It provides a static exit method:

public void CloseApp() {     CoreApplication.Exit(); } 

However, the documentation states the following:

Note Do not use this method to shut down an app outside of testing or debugging scenarios.

Sadly, the reason behind that is left unkown.


Further more, you can use the old-fashioned Application.Exit method (non-static):

public void CloseApp() {     Application.Current.Exit(); } 

Here you should also take a look in the remarks:

Use this method to provide UI that enables users to exit your app. Normally, however, you should not provide this UI because the system automatically manages app lifetime and terminates suspended apps as needed to free resources.

tl;dr: Both Exit methods will terminate the app, rather than suspending it. You should ask yourself if this really is the action you want to do.

like image 134
Herdo Avatar answered Oct 04 '22 14:10

Herdo