Igor Kulman

Windows Phone: run background agent every minute

· Igor Kulman

In both Windows Phone 7 and Windows Phone 8 the background agent is executed approximately every 30 minutes. If you want to run your code more often, for example to create an app showing actual time on the live tile, you are out of luck. Are you?

You can use ScheduledActionService.LaunchForTest to test your background agent without waiting 30 minutes for the system to run it. What if you use this method in the OnInvoke method of your background agent?

protected override void OnInvoke(ScheduledTask task)
{   
    ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromSeconds(60));
    var toast = new ShellToast {Title = DateTime.Now.ToShortTimeString(), Content = "Task Running"};
    toast.Show();
                        
    NotifyComplete();
}

Your background agent gets executed every minute!

I wonder if this code would pass certification. Has anyone tried to use it?

Update: it will not work, see Windows Phone: Don’t call LaunchForTest in Release.

See also