How to schedule a toast notification (Windows Store apps using C#/VB/C++ and XAML)
You can schedule a toast notification to appear at a specific time.
- Windows Runtime
- A working knowledge of toast notification terms and concepts. For more information, see Toast overview.
- The Toast Capable option must be set to "Yes" in your app's manifest to send or receive toast notifications. For more information, see How to opt in for toast notifications.
Windows.UI.Notifications includes the toast APIs.
Before you can specify the delivery time, you must create the notification.
ToastTemplateType toastTemplate = ToastTemplateType.ToastText02; XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);
We won't cover this here because it's the same for a scheduled toast as for a non-scheduled toast. For more information, see Quickstart: Sending a toast notification.
This example specifies that the notification should appear in 3 hours. This example uses the DateTime object.
Send the toast notification content and the scheduled delivery time to the constructor.
ScheduledToastNotification scheduledToast = new ScheduledToastNotification(toastXml, dueTime);
This ID must be 16 characters or less. It can be used later if you want to cancel the notification.
Create the ToastNotifier object, which in turn is used to add your notification to the schedule.
Adding a toast notification that repeats at a specific interval
The following code displays a single toast notification five times, each one minute apart, starting in three hours.
ToastTemplateType toastTemplate = ToastTemplateType.ToastText02; XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate); // Fill in the template with your notification content. Int16 startTimeInHours = 3; DateTime startTime = DateTime.Now.AddHours(startTimeInHours); ScheduledToastNotification recurringToast = new ScheduledToastNotification(toastXml, startTime, 60 * 1000, 5); recurringToast.Id = "Recurring_Toast"; ToastNotificationManager.CreateToastNotifier().AddToSchedule(recurringToast);