Occurs just before an application shuts down, and cannot be canceled.
Assembly: PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
An application can shut down for either of the following reasons:
The user ends the session by logging off or shutting down.
You can detect when application shutdown occurs by handling the event, and perform any additional processing as required.
You can also handle to inspect or change the application exit code when you don't need to call Shutdown explicitly. The exit code is exposed from the ApplicationExitCode property of the ExitEventArgs argument that's passed to the event handler. When the application stops running, the exit code is passed to the operating system for subsequent processing.
If your application handles the SessionEnding event and subsequently cancels it, is not raised and the application continues running in accordance with the shutdown mode.
The exit code can be set from an XAML browser application (XBAP), although the value is ignored.
For XBAPs, is raised in the following circumstances:
An XBAP is navigated away from.
In Internet Explorer 7, when the tab that is hosting the XBAP is closed.
When the browser is closed.
In all cases, the value of the ApplicationExitCode property is ignored.
The following example demonstrates how to:
Handle the event.
Write an entry to an application log in isolated storage.
Persist the application state to isolated storage.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2