Application.Suspending event

Applies to Windows and Windows Phone

Occurs when the application transitions to Suspended state from some other state.

Syntax


public:
event SuspendingEventHandler^ Suspending {
   Windows::Foundation::EventRegistrationToken add(SuspendingEventHandler^ value);
   void remove(Windows::Foundation::EventRegistrationToken token);
}

Event information

Delegate SuspendingEventHandler

Remarks

The system suspends your app whenever the user switches to another app or to the desktop, and resumes your app whenever the user switches back to it. However, the system can also terminate your app while it is suspended in order to free up resources. Therefore, you should handle the Suspending event to perform the following operations:

  • Preserve user session state.
  • Release any exclusive locks on resources.
  • Reduce memory usage if possible. For example, serialize any data that is easy to reconstruct in object form upon reactivation.
  • Save app state.

The Suspending event is the only indication your app will receive prior to termination (if it happens). Because of this, you should store enough session state (such as the current article being read or the current movie playback position) to recreate the exact same experience during activation. The guidance for content creation apps is to save a user’s work early and often but also commit one final save during Suspending. Saving data prior to suspension is useful because the Suspending event handler has only 5 seconds to complete its operation.

If your app is terminated, you can restore the app state in an OnLaunched method override. If your app resumes before it is terminated, the system restores the app state automatically. You should handle the Resuming event only if you need to refresh any displayed content that might have changed while the app is suspended, such as news feeds or the user's location.

Examples

This code example demonstrates a typical usage pattern for this event. This code is used by many of the XAML samples, for example the Input sample, as part of the code-behind for the app.xaml file. If you browse the XAML samples, you can find the source code for the SuspensionManager class APIs as referenced in this code.

No code example is currently available or this language may not be supported.

Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

Windows.UI.Xaml
Windows::UI::Xaml [C++]

Metadata

Windows.winmd

See also

Application
OnActivated
Resuming
Launching and resuming apps

 

 

Show:
© 2014 Microsoft