當我嘗試在windows phone 7.5中添加一個定期任務時,它給了我一個「BNS錯誤:此類型的ScheduledAction的最大數量已被添加。」錯誤,但我沒有添加任何定期任務。該代碼在Windows Phone 8上正常工作,但在WP7.5上引發了這個錯誤。此外,該應用程序安排提醒和警報。後臺代理錯誤WP7
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)
{ }
該應用程序是新安裝的。沒有以前的背景代理已被添加..相同的代碼運行在wp8罰款...我也檢查了計劃任務的計數,它是0 – Timay 2013-04-29 19:33:55