Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Silverlight 3
Application Class
Application Events
 Exit Event
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Silverlight 3

Other versions are also available for the following:
.NET Framework Class Library for Silverlight
Application..::.Exit Event

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

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)
Visual Basic (Declaration)
Public Event Exit As EventHandler
Visual Basic (Usage)
Dim instance As Application
Dim handler As EventHandler

AddHandler instance.Exit, handler
C#
public event EventHandler Exit
XAML Attribute Usage
<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.

XAML
<Application 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    x:Class="SilverlightApplication.App"
    Startup="App_Startup"
    Exit="App_Exit">

</Application>
Visual Basic
Partial Public Class App
    Inherits Application

    Public Sub New()
        InitializeComponent()
    End Sub

    Private Sub App_Startup(ByVal o As Object, ByVal e As StartupEventArgs) Handles Me.Startup
        ' The application has started.
    End Sub

    Private Sub App_Exit(ByVal o As Object, ByVal e As EventArgs) Handles Me.Exit
        ' The application is about to stop running.
    End Sub

End Class
C#
using System; // EventArgs
using System.Windows; // Application

namespace SilverlightApplication
{
    public partial class App : Application
    {
        public App()
        {
            InitializeComponent();
        }

        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.
        }
    }
}

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

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker