2012-12-22 20 views
0

在我的Windows Phone 8應用程序中,我使用ScheduledTaskAgent按計劃執行一些代碼。 在任務代碼期間,我立即開始運行警報。我使用下面的代碼做報警報警代碼在後臺任務中引發無效操作異常

Alarm alarm = new Alarm("Test Alarm"); 
alarm.Content = "My Test alarm"; 
alarm.BeginTime = DateTime.Now.AddSeconds(2); 
alarm.ExpirationTime = alarm.BeginTime.AddSeconds(5); 
alarm.RecurrenceType = RecurrenceInterval.None; 
alarm.Sound = new Uri("/Assets/Beep.wav", UriKind.RelativeOrAbsolute); 

// Add the reminder to the ScheduledActionService 
ScheduledActionService.Add(alarm); 

在scheduledactionservice添加的地方,我得到下面的異常:

System.InvalidOperationException:BNS錯誤:API只能從前臺應用程序調用。

任何幫助?

回答

2

您不能從後臺代理添加計劃任務,只能從應用程序本身添加。您需要從您的UI代碼安排鬧鐘。

+0

明白了,謝謝布萊恩特。 – Mahender