WP7 BackgroundAgent will not start

175 Views Asked by At

I'm facing a wierd problem with my scheduled agent. I created it some weeks ago and it worked on my phone, I tested it and everything was all right. But today I modified it, recompiled, deployed and... it didn't start.

I added LaunchForTest, tried with different timespans... nothing worked. I've ensured that all the assemblies are correctly referenced, that I'm not using any forbidden API... And it won't start. Even with a clean & build, and a clean install. I tried on the emulator and it works.

If anybody has a clue of what could be happening... Thanks.

2

There are 2 best solutions below

2
On

There are three options when Background Agent is not launched: Background Agent is disabled in settings, Battery level is low, Background Agent has crashed two times in row

0
On

It sounds like you didn't delete the old schedule and create a new one.

Make sure you are doing something like this in your app (not the background agent). It will remove any existing one and add it back.

try
{
   PeriodicTask Action = (PeriodicTask)ScheduledActionService.Find(MainPage.AgentName);
   if ( Action != null)
   {
      ScheduledActionService.Remove(MainPage.AgentName);
   }

   ScheduledActionService.Add(periodicTask);
}