Access IndexedDB Metro Javascript App In Background

I am trying to access indexeddb from my application (so that I can update a live tile) in a javascript background job.

I configure the task as follows:

var builder = new Windows.ApplicationModel.Background.BackgroundTaskBuilder(); builder.name = taskName; builder.taskEntryPoint = "js\\task\\backgroundTask.js"; //Run every 8 hours if the device is on AC power var trigger = new Windows.ApplicationModel.Background.MaintenanceTrigger(480, false); builder.setTrigger(trigger); var task = builder.register(); 

The task is as follows:

 (function () { "use strict"; var backgroundTaskInstance = Windows.UI.WebUI.WebUIBackgroundTaskInstance.current; var cancel = false; function doWork() { var key = null, settings = Windows.Storage.ApplicationData.current.localSettings; //todo access db and update tile close(); } if (!cancel) { doWork(); } else { close(); } function onCanceled(cancelSender, cancelReason) { cancel = true; } backgroundTaskInstance.addEventListener("canceled", onCanceled); })(); 

The task works fine, but I cannot work if I can access db (or any application resources). Is this possible, perhaps the way that I missed?

+4
source share
3 answers

According to http://msdn.microsoft.com/en-us/library/windows/apps/hh453270.aspx the in-store WorkerGlobalScope application, which is valid when you are in the background task, makes indexedDB available. IndexedDB works in local appdata, so it should be used like any other application operations.

Generally speaking, background tasks can modify application data and issue updates for tile / toast / badge. As Slace points out, you cannot access other application resources, so appdata is how you exchange data with the main application.

+4
source

I think that background tasks are performed on different threads (so they don’t have the same restrictions on snagging) and cannot access application resources. This is how background tasks are kept alive even when the application is paused, which means that you cannot access application resources.

0
source

You can use the IndexedDB API inside the worker, but then you need to use the synchronization interface .

My experience with Windows 8 developers is that you cannot use the asynchronous API in it. When calling asynchronous calls, called calls will not be called. Also, as mentioned in Kraig, only the API available for the workspace can be used. (You cannot call anything from a window object.)

0
source

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


All Articles