As previously stated, registering an alarm is done via the ScheduledActionService
. When using the ScheduledActionService
, each notification must be given a unique name, or an exception is raised when you try to add it to the service. In the following example, we avoid reregistering a notification by detecting whether a notification with the same name has already been registered. We then use the ScheduledActionService
class’s Add
method to register the alarm, as shown:
Alarm alarm = new Alarm(alarmName)
{
BeginTime = DateTime.Now.AddDays(1),
Content = "A test alarm.",
RecurrenceType = RecurrenceInterval.None,
Sound = new Uri("/Sounds/Alarm.wma", UriKind.Relative),
};
if (ScheduledActionService.Find(alarm.Name) != null)
{
ScheduledActionService.Remove(alarm.Name);
}
ScheduledActionService.Add(alarm);
The BeginTime
property indicates when the alarm is due to occur. RecurrenceInterval.None
specifies that the alarm is not recurring, which need not be specified because it is the default value.
The Alarm.wma audio file is located in the project and has its Build Action set to Content. When the alarm occurs, the audio file is played.
The Alarm
class properties are examined in greater detail in the following section, where you explore the downloadable sample code for this section.
18.216.58.135