How to execute code when Universal Windows Store application closes?

I am developing an application for the Windows 10 Store application, but I cannot find / find out how to check if the user clicked the red close button (top right) or by clicking Alt+ F4. Basically, I want something like this:

private void app_Close(object sender, CloseEventArgs e)
{
     //saves some data in the app :D
}
+4
source share
2 answers

: EDIT :.

If you have a generic application that does not have a MainWindow object, you probably want to click the "Suspend Event":

appObject.Suspending += (s, a) =>
        {
            SaveTheData(); // I really like my data and want it for later too
        };

or

public App()
    {
    /*
        stuff
     */
    Suspending += (s, a) =>
        {
            SaveTheData(); // I really like my data and want it for later too
        };
    }

.: Original :.

MainWindow "", . "" , "" .

theMainWindowObject.Closing += (s,a) =>
    {
        SaveTheData(); // It precious!
    };

- , MainWindow "theMainWindowObject" "this",

, :

public MainWindow()
    {
    // Note: "this." isn't necessary here but it helps me with mental accounting
    this.Closing += (s, a) =>
        {
            Save();
        };
    }

, :

public MainWindow()
    {
    Closing += (s, a) =>
        {
            Properties.Settings.Default.SettingsPopupX = mySettingsPopupObject.GetX();
            Properties.Settings.Default.SettingsPopupY = mySettingsPopupObject.GetY();
            Properties.Settings.Default.Save();
        };
    }
+5

, MSDN: https://msdn.microsoft.com/en-us/library/windows/apps/mt243287.aspx "" Windows Apps. , Windows . ApplicationExecutionState (. ), , ( ) .

, !

0

Source: https://habr.com/ru/post/1620801/


All Articles