Limitations of the background task of the remote application service in UWP

I was wondering what are the limitations of the background task caused by the remote device. Everything I found in the Microsoft documentation was a general limitation of the background task, which is 30 seconds.

But my simple test shows that this is not the case when a service application is called from another device. (I'm not sure about the usual application services, although I did not include them in my test)

Here is my testing method:

I put this code in OnBackgroundActivatedapplications and registered a background task TimeTrigger.

            for (int i = 0; i < 100; i++)
            {
                Common.ToastFunctions.SendToast((i * 5).ToString() + " seconds");
                await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(5));
            }

(And I got a delay, so the task will not be closed unexpectedly due to operations await)

I received toast notifications within 20-25 seconds, and nothing after that. Thus, the process was killed up to 30 seconds, which corresponds to official documentation.

Then I put the same code in RequestReceivedmy event AppServiceConnection, and this code in OnBackgroundActivated(which basically sets up the event RequestReceivedand gets a delay:

        this._backgroundTaskDeferral = args.TaskInstance.GetDeferral();
        args.TaskInstance.Canceled += OnTaskCanceled;
        var details = args.TaskInstance.TriggerDetails as AppServiceTriggerDetails;

        if (details?.Name == "com.ganjine") //Remote Activation
        {
            _appServiceconnection = details.AppServiceConnection;
            _appServiceconnection.RequestReceived += OnRequestReceived;
            _appServiceconnection.ServiceClosed += AppServiceconnection_ServiceClosed;
        }

Then I made a connection and sent some data to this background task from another device (using the Romeo APIs)

This time he did not stop until 30 seconds. My loop was 100iterating, and I got toasts indicating that the background task did not stop and was able to run ~ 500 seconds .

But it was my cycle, he could continue even more with a longer cycle.

? AppService, ?

. , , ( ) . (, , ?). , .

+4
1

? AppService, ?

. . 30 . , , , . , , .

9: : -

+5

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


All Articles