Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Exit Event

Application.Exit Event

Occurs just before an application shuts down and cannot be canceled.

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)

public event EventHandler Exit
<Application Exit="eventhandler"/>

You can detect when an application shuts down by handling the Exit event. This allows your application to perform common application shutdown tasks, including saving data for the next application session and logging.

Important noteImportant Note:

An Exit event handler should not include long-running, re-entrant, or cyclic code, such as resetting the Silverlight plug-in's Source property.

The following code shows how to handle Exit using markup and code-behind.



using System; // EventArgs
using System.Windows; // Application

namespace SilverlightApplication
    public partial class App : Application
        public App()

        private void App_Startup(object sender, StartupEventArgs e)
            // The application has started.

        private void App_Exit(object sender, EventArgs e)
            // The application is about to stop running.


Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

© 2015 Microsoft