uwpwindows-phonewindows-10-universalwindows-10-mobilewindows-8.1-universal

Complicated background work in UWP, is it real?


Usually I work with Android but now I need to make background application/library/service in UWP.

So, I need three background tasks/jobs/services:

  1. Every 15 minutes send POST request to the server
  2. Every 1 minute check some data
  3. Run via push notification a long-running tcp/ip connection which can run about 1 hour (how long can it run?)

I am confused, is it possible for UWP?


Solution

  • The short answer,it is not complicated.

    Every 15 minutes send POST request to the server

    Background tasks can run as frequently as every 15 minutes, and they can be set to run at a certain time by using the TimeTrigger. For more info see Run a background task on a timer.

    Every 1 minute check some data

    Based on battery life considerations if FreshnessTime is set to less than 15 minutes, an exception is thrown when attempting to register the background task. For long running background Task please check Run background tasks indefinitely official document.

    Run via push notification a long-running tcp/ip connection which can run about 1 hour (how long can it run?)

    You could use PushNotificationTrigger to enable them to provide real-time communication with the user even when the app is not in the foreground.

    For creating the Background Task, You could refer this document. And this is official code sample that you could refer.