Shows how to create extended execution sessions using the Windows Runtime extended execution API.
Note: This sample is part of a large collection of UWP feature samples. If you are unfamiliar with Git and GitHub, you can download the entire collection as a ZIP file, but be sure to unzip everything to access shared dependencies. For more info on working with the ZIP file, the samples collection, and GitHub, see Get the UWP samples from GitHub. For more samples, see the Samples portal on the Windows Dev Center.
An app requests an extended execution session when a task requires time to complete before the application is suspended or terminated. Different types of extended execution can be requested during the Suspending state or the Resumed state of the application.
This sample demonstrates the following:
- Creating an extended execution session to extend suspending time and complete saving data.
- Creating an extended execution session to extend foreground time and continue location tracking.
- Creating an extended execution session to extend foreground time and continue an unspecified task.
- Sharing an extended execution session among multiple tasks.
- Handling a denied request for extended execution.
- Handling the revocation of an extended execution session.
See Deploying and running the sample below for instructions on using the sample.
Background Tasks and Extended Execution
Launching, resuming, and background tasks
Support your app with background tasks
Windows.ApplicationModel.ExtendedExecution
Windows.ApplicationModel.Background
Client: Windows 10
Server: Windows Server 2016 Technical Preview
Phone: Windows 10
- If you download the samples ZIP, be sure to unzip the entire archive, not just the folder with the sample you want to build.
- Start Microsoft Visual Studio 2017 and select File > Open > Project/Solution.
- Starting in the folder where you unzipped the samples, go to the Samples subfolder, then the subfolder for this specific sample, then the subfolder for your preferred language (C++, C#, or JavaScript). Double-click the Visual Studio Solution (.sln) file.
- Press Ctrl+Shift+B, or select Build > Build Solution.
Deploying the sample
- Select Build > Deploy Solution.
Deploying and running the sample
- To debug the sample and then run it, press F5 or select Debug > Start Debugging. To run the sample without debugging, press Ctrl+F5 or selectDebug > Start Without Debugging. Since the system will not suspend an app that is being debugged, some scenarios require you to run the sample without debugging.
Unspecified Extended Execution:
- Run the sample without debugging and go to the Unspecified Reason scenario.
- Click Begin Extended Execution.
- Send the program to the background: On Phone, switch to another app. On PC, minimize the app.
- The app continues to display toast notifications.
- Bring the app back to the foreground and the session will continue running.
- Run the sample with debugging.
- Repeat steps 2 through 4 above.
- Use the Lifecycle events menu in the debugger to suspend the app. This simulates a revoke due to SystemPolicy.
Saving Data Extended Execution:
- Run the sample without debugging and go to the Saving Data Reason scenario.
- Send the program to the background: On Phone, switch to another app. On PC, minimize the app.
- The app displays toast notifications while the save operation proceeds, demonstrating that the app was given a longer period of time to save data while suspending.
Location Tracking Extended Execution:
- Run the sample without debugging and go to the Location Tracking Reason scenario.
- Click Begin Extended Execution.
- Send the program to the background: On Phone, switch to another app. On PC, minimize the app.
- The app continues to report your location every 10 seconds.
- Bring the app back to the foreground and the session will continue running.
- Run the sample with debugging.
- Repeat steps 2 through 4 above.
- Use the Lifecycle events menu in the debugger to suspend the app. This simulates a revoke due to SystemPolicy.
Using Multiple Tasks:
- Run the sample without debugging and go to the Using Multiple Tasks scenario.
- Click Begin Extended Execution and Tasks.
- Send the program to the background: On Phone, switch to another app. On PC, minimize the app.
- The app displays toast notifications as each of three Tasks complete.
- Bring the app back to the foreground and the session will continue running.
- Run the sample with debugging.
- Repeat steps 2 through 4 above.
- Use the Lifecycle events menu in the debugger to suspend the app. This simulates a revoke due to SystemPolicy.