0

I have set up a ScheduledTaskAgent with a LaunchForTest (which I know is being called). When I launch the main app, it seems to successfully add the task and OnInvoke runs to completion (calls NotifyComplete), but never seems to run again. I've pared down the OnInvoke to do nothing other than call NotifyComplete, but it still only ever runs the one time following ScheduledActionService.Add and ScheduledActionService.LaunchForTest (with a few seconds' delay).

What could be preventing it from running more than once?

user3380909
  • 113
  • 1
  • 5
  • Found the problem: to get the scheduled agent to repeat on a shorter schedule (for testing), ``#if DEBUG ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromSeconds(30)); #endif`` must be in **both** the application launch (e.g. App constructor) AND the agent OnInvoke. It's not enough to put it only in the application launch. – user3380909 Apr 01 '14 at 20:09

2 Answers2

0

I am assuming it is about PeriodicTask.

You are right. It will run only once and that is because of the LaunchForTest call, wherein you have specified the timespan. After that execution, you have to wait another 30 minutes for it to run.

Are you adding the ScheduledActionService.Add in App.xaml.cs? I mean, on the launch event? You should. If you have that, then you could run the app again, and it will invoke the task agent.

Rajeev Nair
  • 759
  • 8
  • 20
0

If you are hitting the breakpoint even once that means that you are correctly set up. You have to remember that ScheduledActionService.LaunchForTest is just a function that you can call under debugger. It will not work when the app is released.

Basically, there is no way to fire the background agent, you can register it and then forget it. Windows Phone OS will invoke it periodically.

If you want to debug the periodic task multiple times then you can put LaunchForTest in a loop with delay.

Anz
  • 594
  • 1
  • 4
  • 15