Windows Phone 7.5 で定期的なタスクを追加しようとすると、「BNS エラー: このタイプの最大数の ScheduledActions が既に追加されています。」というメッセージが表示されます。定期的なタスクを追加していない間にエラーが発生しました。このコードは Windows Phone 8 では問題なく動作しますが、WP7.5 ではこのエラーが発生します。また、アプリはリマインダーとアラームをスケジュールします。
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)
{ }