I’m creating an app for windows phone OS 7.1 to learn about this platform. When creating alarm app, i faced this strange error: When i set an alarm using ScheduledActionService.Add(myAlarm), alarm never goes off at the selected time. I set the beginTime = now + 10 seconds, then i waited for 2 minutes with no luck. However when i add another alarm in runtime, after the selected time of the last alarm, then the last alarm will goes off.
Below is the code of my createAlarm function. I’ve done some searches but found no solution.
private void createAlarm(double time, string message)
{
var myAlarm = new Alarm(System.Guid.NewGuid().ToString())
{
Content = message,
BeginTime = DateTime.Now.AddSeconds(time),
ExpirationTime = DateTime.Now.AddSeconds(time + 10.0)
};
myAlarm.Sound = new Uri("/Sounds/02 Ha Trang.mp3", UriKind.Relative);
myAlarm.RecurrenceType = RecurrenceInterval.None;
ScheduledActionService.Add(myAlarm);
}
This is a known problem. Alarms go off with accuracy of 30 seconds. So is the case with the reminders. You may actually get accurate results sometimes, but overall, it’s not reliable to have frequent alarms or reminders. The lack of accuracy is probably to keep resource consumption low. (Remember, alarms work in background.) The first alarm is fired when second one is set because system suddenly ‘realizes’ that an alarm is already overdue. It would be a good practice to separate those with at least a minute.
On the other hand, if you really need to have a beep at really small intervals, you will have to use something more ‘foreground’ like timer.