Wednesday, 15 April 2015

c# - Background Task doesn't start -



c# - Background Task doesn't start -

i trying figure out why backgroundtask won't start, have no idea, i'm doing wrong.

what trying do: want have automated background task download 5 latest items through webapi (data couple kb). after downloading check local file, see if there new items available. if so, want create badge on livetile number of new items.

i have next code:

private backgroundtaskregistration schedulebackgroundtask() { foreach (var cur in backgroundtaskregistration.alltasks) { if (cur.value.name == "timetriggeredtask") { homecoming (backgroundtaskregistration)(cur.value); } } var builder = new backgroundtaskbuilder(); builder.name = "timetriggeredtask"; builder.taskentrypoint = "tasks.updateitemtask"; builder.settrigger(new maintenancetrigger(15, false)); builder.addcondition(new systemcondition(systemconditiontype.internetavailable)); builder.addcondition(new systemcondition(systemconditiontype.usernotpresent)); backgroundtaskregistration task = builder.register(); homecoming task; }

and job looks this:

namespace tasks { public sealed class updateitemtask : ibackgroundtask { public async void run(ibackgroundtaskinstance taskinstance) { debug.writeline("starting"); backgroundtaskdeferral _deferral = taskinstance.getdeferral(); datahandler datahandler = new datahandler(); bindablecollection<geekandpokeitemviewmodel> latestitemsonline = await datahandler.getdata("10"); bindablecollection<geekandpokeitemviewmodel> latestitemslocal = await datahandler.getlocaldata(); int difference = latestitemsonline.except(latestitemslocal).count(); if (difference > 0) { badgeupdatemanager.createbadgeupdaterforapplication().clear(); badgenumericnotificationcontent badgecontent = new badgenumericnotificationcontent((uint)difference); // send notification app's application tile badgeupdatemanager.createbadgeupdaterforapplication().update(badgecontent.createnotification()); } _deferral.complete(); } } }

in appmanifest backgroundtask extended task "timer" , right entrypoint.

all code in 1 project.

even debugger attached (debug programme without starting app, , forcefulness fire task), wont nail task (or breakpoint) , in eventviewer gives result of:

the background task entry point tasks.updateitemtask , name timetriggeredtask failed activate error code 0x80010008.

i've been checking the samples of ms background tasks, not helping. suggest isn't hard cant work.

i got working!!

first: i've moved tasks new assembly windows rt component type , added reference in winrt app.

second: had backgroundtaskregistration , updateitemtask in 1 cs file, task sealed. needed set backgroundtaskregistration sealed, in order compile. 1 time forcefulness fire trigger hits breakpoint...

c# windows-runtime

No comments:

Post a Comment