Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12141

UWP background tasks: Does it run indefinitely? How to check if it is already running?

$
0
0

From a UWP app I start the following UWP background task using BackgroundTaskBuilder:

namespace Background.UWP{    public sealed class BackgroundTask : IBackgroundTask    {        private WatchLoop _watchLoop;        public void Run(IBackgroundTaskInstance taskInstance)        {            ApplicationTriggerDetails details = taskInstance.TriggerDetails as ApplicationTriggerDetails;            var arg = details.Arguments["MyArg"].ToString();            // Start an infinite loop that periodically does some checks             _watchLoop = new WatchLoop(arg, new ToastNotification());            _watchLoop.Start();            }        }}

First question: Does this background task run indefinitely if not cancelled by certain check conditions?

Second question: In my UWP app, how can I check if this background task is already running? I want to avoid starting a second background task. Is there a global handle of this task that I can store (serialized) in global storage (e.g. database) and use in the next instance of the UWP app?


Viewing all articles
Browse latest Browse all 12141

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>