2011-12-25 92 views
2

在我的应用Application_Exit事件中,我试图使用ScheduledActionService设置闹钟。这部作品在其他代码不错,但在这里它保持与消息E_INVALIDARG在Windows Phone 7中设置闹钟

这里抛出一个ArgumentException是代码

string alarmName = Guid.NewGuid().ToString(); 
const string cookingClockAlarm = "Cooking clock alarm"; 
DateTime dueTime = DateTime.Now.AddSeconds(10); 
var alarm = new Alarm(alarmName) 
        { 
         Content = cookingClockAlarm, 
         BeginTime = dueTime, 
         ExpirationTime = dueTime.AddSeconds(3), 
         RecurrenceType = RecurrenceInterval.None 
        }; 
// Register the alarm with the system. 
ScheduledActionService.Add(alarm);//here I get an exception 

任何想法,我做错了什么?

+0

有趣的是,我在调用ScheduledActionService.Find时遇到了与应用程序关闭时相同的问题。 http://stackoverflow.com/questions/10510152/scheduledactionservice-find-throws-argumentexception – 2012-06-09 07:51:55

回答

3

我在Application_Closing方法中添加了这段代码,它没有抛出错误。就像在退出事件中那样,安排警报已经太迟了。

+0

谢谢!那就是诀窍。显然退出太晚了。 – Gluip 2011-12-25 15:32:58