I have added Scheduled Task Agent in my WP7 app to remind the periodically. While testing after 2-3 days the agent will be off and it won’t turn back again even if i open the app and start the task again.
Below is what I have tried in my ScheduledTaskAgent:
protected override void OnInvoke(ScheduledTask task)
{
DateTime time = DateTime.Now;
if (time.Hour > 6 && time.Hour < 23)
{
getContent();
if (task.Name.Equals("PeriodicTaskDemo", StringComparison.OrdinalIgnoreCase))
{
ShellToast toast = new ShellToast();
Mutex mutex = new Mutex(true, "ScheduledAgentData");
mutex.WaitOne();
IsolatedStorageSettings setting = IsolatedStorageSettings.ApplicationSettings;
toast.Title = setting["ScheduledAgentData"].ToString();
mutex.ReleaseMutex();
toast.Content = "You are being notified!!";
toast.Show();
}
NotifyComplete();
}
}
The battery saver won’t disable you background task from starting again. The only reasons your agent was disabled: