Learn how to refresh displayed content when the system resumes your Windows Store app. The example in this topic registers an event handler for the Resuming event.
Roadmap: How does this topic relate to others? See:
Instructions
Step 1: Register the resuming event handler
Register to handle the Resuming event, which indicates that the user switched away from your app and then back to it.
partial class MainPage { public MainPage() { InitializeComponent(); Application.Current.Resuming += new EventHandler<Object>(App_Resuming); } }
Step 2: Refresh displayed content after suspension
When your app handles the Resuming event, it has the opportunity to refresh its displayed content. Because this event is not raised in the UI thread, a dispatcher must be used inject an update to the UI.
partial class MainPage { private void App_Resuming(Object sender, Object e) { // TODO: Refresh network data } }
Remarks
The system suspends your app whenever the user switches to another app or to the desktop. The system resumes your app whenever the user switches back to it. When the system resumes your app, the content of your variables and data structures is the same as it was before the system suspended the app. The system restores the app exactly where it left off, so that it appears to the user as if it's been running in the background. However, the app may have been suspended for a significant amount of time, so it should refresh any displayed content that might have changed while the app was suspended, such as news feeds or the user's location.
If your app doesn't have any displayed content to refresh, there's no need for it to handle the Resuming event.
A note about debugging using Visual Studio: When your app is attached to the Visual Studio debugger, you can send it a resume event. Make sure the Debug Location toolbar is being shown, and click the drop-down next to the Suspend icon. Then choose Resume.
Related topics
- Tasks
- How to activate an app
- How to suspend an app
- Conceptual
- Application lifecycle
- Guidelines
- Guidelines for app suspend and resume
- Reference
- Windows.UI.Xaml.Application
Build date: 10/26/2012