我正在创建一个带有计时器的应用程序。如果用户离开应用程序,我想显示一个吐司通知(或某种通知),这样他们就知道计时器结束了。我将"PeriodicTask“与".FromSeconds”一起使用,但它似乎没有在指定的时间触发它。
PeriodicTask periodicTask = new PeriodicTask("TaskTest");
periodicTask.Description = "Task";
try
{
IsolatedStorageSettings.ApplicationSettings["TimerForSchedule"] = TimeNum;
ScheduledActionService.Add(periodicTask);
ScheduledActionService.LaunchForTest("TaskTest", TimeSpan.FromSeconds(((TimeNum*60))));
}关于调度代理项目的"OnInvoke“方法,我有以下几点:
protected override void OnInvoke(ScheduledTask task)
{
if (task.Name == "TaskTest")
{
int time = Convert.ToInt32(IsolatedStorageSettings.ApplicationSettings["TimerForSchedule"]);
bool periodic = (bool)(task is PeriodicTask);
ShellToast toast = new ShellToast();
toast.Title = "Done";
toast.Content = "Timer is over";
toast.Show();
}
NotifyComplete();
ScheduledActionService.Remove("TaskTest");
}一切似乎都正常启动,因为我确实收到了通知,但我没有在预期的时间收到它。
任何帮助都将不胜感激。
发布于 2013-01-06 07:15:46
我认为你设置的运行PeriodicTask的时间只是对操作系统的一个提示,这并不意味着它会在那个时候准确地启动它。
发布于 2013-01-05 08:56:38
你的应用是在前台运行的吗?如果是这样,ShellToast将不会出现。你的应用程序必须在后台才能显示。在我的另一个@ How can I create a shelltoast?上了解更多关于该问题的信息和潜在的解决方法
https://stackoverflow.com/questions/14164358
复制相似问题