I need it for their own exit button. Tell me please? I try this: this.Close(); //or Exit dont work(
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.