我正在尝试ScheduledActionService
在 Windows Phone 应用程序中添加两个提醒,如下所示:
private void button1_Click(object sender, RoutedEventArgs e)
{
if (ScheduledActionService.Find("PomodoroAkshay") != null)
{
ScheduledActionService.Remove("PomodoroAkshay");
this.Storyboard_Copy1.Begin();
this.textBlock1.Text = "It's stopped!";
if (ScheduledActionService.Find("BreakAkshay") != null)
{
ScheduledActionService.Remove("BreakAkshay");
}
}
else
{
if (ScheduledActionService.Find("BreakAkshay") != null)
{
ScheduledActionService.Remove("BreakAkshay");
}
Reminder brk = new Reminder("BreakAkshay");
brk.Title = "BreakUP";
brk.Content = "Time up!";
brk.BeginTime = DateTime.Now.AddSeconds(20);
ScheduledActionService.Add(brk);
Reminder pdro = new Reminder("PomodoroAkshay");
pdro.Title = "PomodoroUP";
pdro.Content = "Time for break!";
pdro.BeginTime = DateTime.Now.AddSeconds(5);
ScheduledActionService.Add(pdro);
this.Storyboard1.Begin();
this.textBlock1.Text = "It's running!";
}
}
当我按下button1
重新开始时,else
会按预期触发。但是,我收到了三个提醒。其中两个(PomodoroAkshay
和BreakAkshay
)在五秒后触发。此外,BreakAkshay
按预期在 20 秒后触发。但是,我只想在 5 秒后触发一次提醒,在 20 秒后触发第二次提醒。我哪里错了?
附加信息:该语句if
清除提醒,以便button1
充当切换按钮。