When I try to add a periodic task in windows phone 7.5 it gives me a "BNS Error: The maximum number of ScheduledActions of this type have already been added." error while i haven't added any periodic task. The code works fine on Windows phone 8 but raises this error on WP7.5. Also the app schedules reminders and alarms.
string periodicTaskName = "myperiodictask";
PeriodicTask periodicTask = ScheduledActionService.Find(periodicTaskName) as PeriodicTask;
if (periodicTask != null)
{
try
{
ScheduledActionService.Remove(periodicTaskName);
}
catch (Exception)
{ }
}
periodicTask = new PeriodicTask(periodicTaskName);
periodicTask.Description = "Updates LiveTile, Sessions and Assignments";
periodicTask.ExpirationTime = DateTime.Now.AddDays(10);
try
{
ScheduledActionService.Add(periodicTask);
}
catch (InvalidOperationException exception)
{
if (exception.Message.Contains("BNS Error: The action is disabled"))
MessageBox.Show("Background agents have been disabled by the user.");
if (exception.Message.Contains("BNS Error: The maximum number of ScheduledActions of this type have already been added."))
MessageBox.Show("maximum number of ScheduledActions of this type have already been added!");
}
catch (SchedulerServiceException)
{ }