Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Application.ShutdownMode Property

Gets or sets the condition that causes the Shutdown method to be called.

Namespace: System.Windows
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

public:
property ShutdownMode ShutdownMode {
	ShutdownMode get ();
	void set (ShutdownMode value);
}
/** @property */
public ShutdownMode get_ShutdownMode ()

/** @property */
public void set_ShutdownMode (ShutdownMode value)

public function get ShutdownMode () : ShutdownMode

public function set ShutdownMode (value : ShutdownMode)

<object ShutdownMode="ShutdownMode" .../>

Property Value

A ShutdownMode enumeration value. The default value is OnLastWindowClose.

Applications stop running only when the Shutdown method of the Application is called. Shut down can occur implicitly or explicitly, as specified by the value of the ShutdownMode property.

If you set ShutdownMode to OnLastWindowClose, Windows Presentation Foundation (WPF) implicitly calls Shutdown when the last window in an application closes, even if any currently instantiated windows are set as the main window (see MainWindow).

A ShutdownMode of OnMainWindowClose causes Windows Presentation Foundation (WPF)to implicitly call Shutdown when the MainWindow closes, even if other windows are currently open.

The lifetime of some applications may not be dependent on when the main window or last window is closed, or may not be dependent on windows at all. For these scenarios you need to set the ShutdownMode property to OnExplicitShutdown, which requires an explicit Shutdown method call to stop the application. Otherwise, the application continues running in the background.

ShutdownMode can be configured declaratively from XAML or programmatically from code.

This property is available only from the thread that created the Application object.

The following example shows how to configure ShutdownMode to specify that an application must be closed explicitly.

<Application
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    StartupUri="MainWindow.xaml"
    ShutdownMode="OnExplicitShutdown"
    >
</Application>

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft