Background Agent in UWP

2019-09-10 10:24发布

问题:

In Windows 8.1 and WP 8.1, there was a slight difference between the way Background Agent used to work:

WinRT: In WinRT, in most cases the OS will not terminate the background agent when the background agent exhausts its quota. Instead it will simply suspend the agent and allow it to continue later. The suspension is done without any warning like an event being raised or callback called. The OS will not stop the background agent when it becomes idle (for example when waiting for a command to the server to respond).

Win Phone: In Win Phone, the OS will terminate the background agent when the background agent exhausts its quota. This termination will be done with no warning. In Win Phone, the OS will stop the background agent when the background agent is found to be idle . In this situation the OS will raise IBackgroundTaskInstance.Canceled.

My question is, is there any such difference between Windows 10 mobile and Windows 10 desktop?

回答1:

In windows 10 Background Agent has been replaced with Background Task. Whatever the type of W10 device (mobile or desktop) it's running on, a standard background task will have 5 seconds to complete its job after receiving the cancel event. Once the 5 seconds have elapsed, the background task will be terminated. The cancel event may be triggered by the user or by the system if quotas (CPU, memory or network) have been exceeded. What is variable from one W10 device to another are both the Memory and Network thresholds used to terminate the task. If you want to learn more about W10 Background tasks, I highly encourage you to watch this video that was made by Microsoft during Ignite 2015 event.