Reputation: 20715
I'm trying to create a background task for my JavaScript Metro app. I added these to the default.js
file:
function RegisterBackgroundTask(taskEntryPoint, taskName, trigger, condition) {
// Check for existing registrations of this background task.
var taskRegistered = false;
var background = Windows.ApplicationModel.Background;
var iter = background.BackgroundTaskRegistration.allTasks.first();
var hascur = iter.hasCurrent;
while (hascur) {
var cur = iter.current.value;
if (cur.name === taskName) {
taskRegistered = true;
break;
}
hascur = iter.moveNext();
}
// If the task is already registered, return the registration object.
if (taskRegistered == true) {
return iter.current;
}
// Register the background task.
var builder = new background.BackgroundTaskBuilder();
builder.Name = taskName;
builder.TaskEntryPoint = taskEntryPoint;
builder.setTrigger(trigger);
if (condition != null) {
builder.addCondition(condition);
}
var task = builder.register();
return task;
}
var trigger = new Windows.ApplicationModel.Background.SystemTrigger(Windows.ApplicationModel.Background.SystemTriggerType.timeZoneChange, false);
RegisterBackgroundTask("js\\bgtask.js", "test", trigger);
This is my bgtask.js
:
(function () {
"use strict";
var backgroundTaskInstance = Windows.UI.WebUI.WebUIBackgroundTaskInstance.current;
function doWork() {
// Write JavaScript code here to do work in the background.
console.log("task done");
close();
}
doWork();
})();
This is my app manifest:
When I change the timezone, nothing happened. I checked the event log and there is an error:
The background task with entry point and name failed to activate with error code 0x80040154.
What did I do wrong?
Upvotes: 1
Views: 550
Reputation: 11
builder.Name = taskName;
builder.TaskEntryPoint = taskEntryPoint;
should be
builder.name = taskName;
builder.taskEntryPoint = taskEntryPoint;
Upvotes: 1