This sample shows you how to create extended execution sessions using the Windows Runtime extended execution API.
Note The Universal Windows app samples require Visual Studio 2015 to build and Windows 10 to execute.
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.
- 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 2015 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 2015 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 to cause a revoke due to Resume.
- 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 to cause a revoke due to Resume.
- 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.
See the following topics for step-by-step information about using extended execution: