我正在尝试在 javascript 后台任务中从我的应用程序访问 indexeddb(因此我可以更新动态磁贴)。
我正在设置这样的任务:
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();
任务如下所示:
(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);
})();
该任务似乎工作正常,但我无法确定是否可以访问数据库(或任何应用程序资源)。这种事情甚至可能吗,如果是的话,我错过了什么?