报警吐司通知windows metro app

时间:2013-11-28 11:10:00

标签: c#

我尝试下面的代码使用吐司发出警报通知,我需要知道如何每天或特定日重复:

 DateTime dateTime = Convert.ToDateTime(time.ToString());
                 DateTime dateNow = DateTime.Now;
                 TimeSpan timenow = new TimeSpan(dateNow.Hour, dateNow.Minute, dateNow.Second);
                 double totalSocunds = time.TotalSeconds - timenow.TotalSeconds;
                 int sec = Convert.ToInt32(totalSocunds);
                 if (sec < 0)
                 {
                     sec = sec* -1;
                 }
                 else
                 {
                     sec = sec *1;
                 }
                 TimeSpan second = TimeSpan.FromSeconds(totalSocunds);
                 var customAlarmScheduledToast = new                    Windows.UI.Notifications.ScheduledToastNotification(toastDOM,DateTime.Now.AddSeconds(sec));
                 toastNotifier

.AddToSchedule(customAlarmScheduledToast);

1 个答案:

答案 0 :(得分:0)

您需要注册后台任务,并选择适当的计划。后台任务负责检查是否需要创建通知,并在必要时创建通知。

在WinRT中创建后台任务:http://msdn.microsoft.com/en-us/library/windows/apps/hh977056.aspx