ScheduledToastNotification Constructors

Definition

Overloads

ScheduledToastNotification(XmlDocument, DateTime)

Creates and initializes a new instance of a ScheduledToastNotification that will be displayed only once.

ScheduledToastNotification(XmlDocument, DateTime, TimeSpan, UInt32)

Deprecated in Windows 10. On Windows 8 systems, creates and initializes a new instance of a ScheduledToastNotification that re-appears after a specified time after initially appearing. On Windows 10, this functions equivalently to ScheduledToastNotification(XmlDocument, DateTime). To achieve the same snooze interval behavior in Windows 10, you can use buttons on your toasts.

ScheduledToastNotification(XmlDocument, DateTime)

Creates and initializes a new instance of a ScheduledToastNotification that will be displayed only once.

public:
 ScheduledToastNotification(XmlDocument ^ content, DateTime deliveryTime);
 ScheduledToastNotification(XmlDocument const& content, DateTime const& deliveryTime);
public ScheduledToastNotification(XmlDocument content, System.DateTimeOffset deliveryTime);
function ScheduledToastNotification(content, deliveryTime)
Public Sub New (content As XmlDocument, deliveryTime As DateTimeOffset)

Parameters

content
XmlDocument

The XML that defines the toast notification content.

deliveryTime
DateTime DateTimeOffset

The date and time that Windows should display the toast notification. You must call AddToSchedule before this time.

Examples

The following example shows a toast notification scheduled to display in one hour, including the use of this constructor to create the notification.

var Notifications = Windows.UI.Notifications;
var currentTime = new Date();
var seconds = 60;
var dueTime = new Date(currentTime.getTime() + seconds * 60 * 1000);
var idNumber = Math.floor(Math.random() * 100000000);  // Generates a unique ID number for the notification.

// Set up the notification text.
var toastXml = Notifications.ToastNotificationManager.getTemplateContent(Notifications.ToastTemplateType.toastText02);
var strings = toastXml.getElementsByTagName("text");
strings[0].appendChild(toastXml.createTextNode(This is a scheduled toast notification));
strings[1].appendChild(toastXml.createTextNode("Received: " + dueTime.toLocaleTimeString()));

// Create the toast notification object.
var toast = new Notifications.ScheduledToastNotification(toastXml, dueTime);
toast.id = "Toast" + idNumber;

// Add to the schedule.
Notifications.ToastNotificationManager.createToastNotifier().addToSchedule(toast);

See also

Applies to

ScheduledToastNotification(XmlDocument, DateTime, TimeSpan, UInt32)

Deprecated in Windows 10. On Windows 8 systems, creates and initializes a new instance of a ScheduledToastNotification that re-appears after a specified time after initially appearing. On Windows 10, this functions equivalently to ScheduledToastNotification(XmlDocument, DateTime). To achieve the same snooze interval behavior in Windows 10, you can use buttons on your toasts.

public:
 ScheduledToastNotification(XmlDocument ^ content, DateTime deliveryTime, TimeSpan snoozeInterval, unsigned int maximumSnoozeCount);
 ScheduledToastNotification(XmlDocument const& content, DateTime const& deliveryTime, TimeSpan const& snoozeInterval, uint32_t const& maximumSnoozeCount);
public ScheduledToastNotification(XmlDocument content, System.DateTimeOffset deliveryTime, System.TimeSpan snoozeInterval, uint maximumSnoozeCount);
function ScheduledToastNotification(content, deliveryTime, snoozeInterval, maximumSnoozeCount)
Public Sub New (content As XmlDocument, deliveryTime As DateTimeOffset, snoozeInterval As TimeSpan, maximumSnoozeCount As UInteger)

Parameters

content
XmlDocument

The XML that defines the toast notification content.

deliveryTime
DateTime DateTimeOffset

The date and time that Windows should first display the toast notification. You must call AddToSchedule before this time.

snoozeInterval
TimeSpan TimeSpan

The amount of time between occurrences of the notification. To be valid, this value must be no less than 60 seconds and no more than 60 minutes.

maximumSnoozeCount
UInt32

unsigned int

uint32_t

The maximum number of times to display this notification. Valid values range from 1 to 5.

Examples

The following example shows a toast notification scheduled to display in one hour, including the use of this constructor to create the notification, specifying a snooze interval of 60 seconds and a maximum of five times to show the notification.

var Notifications = Windows.UI.Notifications;
var currentTime = new Date();
var seconds = 60;
var dueTime = new Date(currentTime.getTime() + seconds * 60 * 1000);
var idNumber = Math.floor(Math.random() * 100000000);  // Generates a unique ID number for the notification.

// Set up the notification text.
var toastXml = Notifications.ToastNotificationManager.getTemplateContent(Notifications.ToastTemplateType.toastText02);
var strings = toastXml.getElementsByTagName("text");
strings[0].appendChild(toastXml.createTextNode(This is a scheduled toast notification));
strings[1].appendChild(toastXml.createTextNode("Received: " + dueTime.toLocaleTimeString()));

// Create the toast notification object.
var toast = new Notifications.ScheduledToastNotification(toastXml, dueTime, 60 * 1000, 5);
toast.id = "Toast" + idNumber;

// Add to the schedule.
Notifications.ToastNotificationManager.createToastNotifier().addToSchedule(toast);

Remarks

This type of snooze interval scheduled toast notification is good for a snooze alarm-like functionality. For instance, the notification could be displayed every five minutes until the maximum snooze count is reached, unless the notification is explicitly removed from the schedule by your app.

Important

Your app is responsible for removing the notification from the schedule once the user activates the notification through a touch or click. Failure to do so can cause the notification to re-appear until the maximum snooze count is reached, even if the user has already dealt with it.

If you want to schedule long snooze intervals like months or years, we recommend that you use individual scheduled toasts rather than this method. That will avoid timing errors caused by daylight savings time or leap years.

The following code shows a call to this method that displays a toast beginning at myData every five minutes for a maximum of three times.

new ScheduledToastNotification(toast1, myDate, 60000, 3)

See also

Applies to