定期的に通知するために、WP7 アプリにスケジュールされたタスク エージェントを追加しました。2 ~ 3 日後にテストしている間、エージェントはオフになり、アプリを開いてタスクを再度開始しても元に戻りません。以下は、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();
}
}