c# - Windows 8 Background Task Progress Handler Not Activating -
i've written background task in win 8 app i'm working on periodically check new items in feeds. task works , if app runs, fires off it's completion handler. however, cannot progression event handler fire. i'm using helper class register event/re-attach handlers
public static async void registerbackgroundtask(string taskname, string entrypoint, uint checktime, backgroundtaskcompletedeventhandler completionmethod, backgroundtaskprogresseventhandler progresshandler = null) { var backgroundaccessstatus = await backgroundexecutionmanager.requestaccessasync(); if (backgroundaccessstatus == backgroundaccessstatus.allowedmayuseactiverealtimeconnectivity || backgroundaccessstatus == backgroundaccessstatus.allowedwithalwaysonrealtimeconnectivity) { foreach (var task in backgroundtaskregistration.alltasks) { if (task.value.name == taskname) { // re-register progress completion event handler. task.value.completed += completionmethod; task.value.progress += progresshandler; return; // task registered, no need set again. } }... progress code: private async void onbackgroundtaskprogress(ibackgroundtaskregistration task, backgroundtaskprogresseventargs e) { await dispatcher.runasync(windows.ui.core.coredispatcherpriority.normal, () => { uint percentage = e.progress; debug.writeline("background task progress: " + e.progress); subscriptionmanager manager = (subscriptionmanager)app.current.resources["submanager"]; var localsettings = windows.storage.applicationdata.current.localsettings; if ((bool)localsettings.values["currentlycheckingpodcast"]) { if (podcastupdatestatus.visibility == windows.ui.xaml.visibility.collapsed) { podcastupdatestatus.visibility = windows.ui.xaml.visibility.visible; } podcastupdatestaustext.text = (string)localsettings.values["currentcheckname"] + " " + (int)localsettings.values["checkno"] + "/" + manager.subscriptions.count; } if (e.progress == 100) { podcastupdatestatus.visibility = windows.ui.xaml.visibility.collapsed; } }); }
and registration code:
backgroundtaskhelpers.registerbackgroundtask("tileupdater", "narrowcastbackgroundtasks.tileupdater", checktimeuint, onbackgroundtaskcomplete, onbackgroundtaskprogress);
any appreciated!
i figured out missing: progress event handler fired when set progress property in background task's instance.
Comments
Post a Comment