Before completing the background task of Windows Phone 8.1

My background task takes a lot of time, and the OS just kills it. I am trying to sync my contacts online, here is what I am doing:

  • Get all contacts from the phone book (takes ~ 1 second)

  • Upload them to the server (~ 2 seconds)

  • Get all contacts from the server (~ 2-3 seconds)

  • Delete all contacts from ContactStore (ContactStore.DeleteAsync sometimes takes 1 minute)

  • Create ContactStore and import all contacts) (~ 1-2 minutes for 1000 contacts)

I have ~ 100 contacts and it works well, but I wanted to test with ~ 1000 contacts, and it does not complete every time. I use MaintenanceTrigger, but I think it is too much for a background task, but I need confirmation of this. MaintenanceTrigger tasks must be enabled to perform more demanding tasks, so why does the OS kill my background job?

+5
source share
3 answers

Take a look at this link: https://msdn.microsoft.com/en-us/library/windows/apps/hh202942(v=vs.105).aspx

Resource-intensive tasks are limited to 10 minutes.

Before starting a task, the following restrictions must be met. If the device stops fulfilling these restrictions, the agent stops immediately.

  • External Power Required
  • Non-cellular calling required
  • Minimum power consumption
  • Device screen lock required
  • Active phone call
  • Unable to change network to cellular.

In addition, there is also a memory cap of 11mb and 20mb respectively for low / high level devices.

From your description above, the most likely IMO scenario is a memory cap. Perhaps this post will help you learn about using a background task in memory: How to get available memory or use it in C #

Key changes in memory limitations starting with Windows Phone 8.1 are (found here ):

  • All front-end Windows Phone 8 apps are handled the same. We no longer have memory for XNA, native, or Silverlight applications.
  • Windows Phone 8.1 applications (including Silverlight 8.1 and Windows Runtime applications) have slightly higher values โ€‹โ€‹than Windows Phone 8 applications.
  • Memory points for all types of applications, including continuous background execution (CBE), increase with increased memory.
  • There are no more caps "by default" and "above" - โ€‹โ€‹there is only a default restriction.
  • The manifest entry ID_FUNCCAP_EXTEND_MEM is ignored for all applications running on Windows Phone 8.1.
  • The manifest entry ID_REQ_MEMORY_300 is still valid, but you must really run the application on all devices.
  • Below is the new equivalent of ID_REQ_MEMORY_300. This entry should be added to the AppX manifest (and not to WMAppManifest).
+3
source

Finally, my task was canceled due to ExecutionTimeExceeded, so this is the problem. It seems like trying to import ~ 1000 contacts into ContactStore takes ~ 12 minutes, which is too big for a background task. I have to force the user to open the application and complete the import. Thank you for your help.

+3
source

erm ... may be stupid, but ...

"Background tasks that use a maintenance trigger are only performed when the system is connected to AC power." Taken from MSDN

Can it be connected to the network when it is working ?, and not connected when it is not working?

EDIT: Consider how busy the phone is when you try to sync contacts? Do you make the app always run in the background with Battery Saver?

You could do something like this to find out how busy your phone is ... or it could be a battery saver stopping your application, if there are size restrictions, etc. achieved ...

Taken from here ...

var result = await BackgroundExecutionManager.RequestAccessAsync(); if (result == BackgroundAccessStatus.Denied) { // Handle this if it is important for your app. } 

"If the result is rejected, the phone considers that it has too many background tasks. In this case, you can ask your users to go to the Battery saver application and make the application work in the background, even if the phone does not work, I want to ..."

+1
source

Source: https://habr.com/ru/post/1243471/


All Articles