Javascript function to find background task by name on Windows 8

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
FindTask: function (taskName) {
    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) {
            return cur;
        }
 
        hascur = iter.moveNext();
    }
 
    return null;
}