2011-12-25 93 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