我在市场上部署了一个Windows Phone 7应用程序,通过PeriodicTask后台代理更新其Live Tile.
一个用户报告的问题是,磁贴在工作一段时间后不再更新.
当他们检查手机上的后台任务时,它被禁用,并且选中"下次打开它时为此应用程序重新打开后台任务"复选框.
打开应用程序并再次尝试引脚操作后,后台任务尚未恢复.
我怀疑这可能与我在App Hub中看到的两个崩溃报告有关:
问题功能:Microsoft.Phone.Scheduler.SystemNotificationInterop.CheckHr
异常类型:ArgumentException
堆栈跟踪:
帧图像功能偏移
0 coredll.dll xxx_RaiseException 19
1 mscoree3_7.dll WatsonUnhandledManagedException 296
2 mscoree3_7.dll Dbg_NotifyManagedException 93
3 mscoree3_7.dll FirstPassException 1044
4 TransitionStub 0
5 Microsoft.Phone.Scheduler.SystemNotificationInterop.CheckHr 248
6 Microsoft.Phone.Scheduler.SystemNotificationInterop .GetNotificationByID 156
7 Microsoft.Phone.Scheduler.ScheduledActionService.Find 276
8 MyApp.Agents.TaskIsActive 60
9 MyApp.MainPage.SetupApplicationBar 44
10 MyApp.MainPage.MainPage_Loaded 100
11 MS.Internal.CoreInvokeHandler.InvokeEventHandler 3660
12 MS.Internal.JoltHelper .FireEvent 1348
13 mscoree3_7.dll IL_CallManaged 884
14 mscoree3_7.dll IL_CallDelegateInternal 176
15 mscoree3_7.dll makeComPlusCall 5255
16 mscoree3_7.dll makeComPlusCallReturnInt 21
17 0
18 agcore.dll CCoreServices :: CLR_FireEvent 385
对Microsoft.Phone.Scheduler.ScheduledActionService.Find的调用导致ArgumentException.
我调用Find方法的name参数来自a,private const string因此每个调用的值都是相同的.
我是否应该捕获此异常并假设后台代理不存在或是否表示代理有问题?
在此阶段,我无法在模拟器中运行应用程序时重现异常.
"当后台代理按顺序崩溃两次时,它会从调度中删除"
我试过故意在每次调用时崩溃ScheduledAgent,如下所示:
protected override void OnInvoke(ScheduledTask task)
{
UpdateTile();
#if DEBUG
// If we're debugging, fire the task again
ScheduledActionService.LaunchForTest("MyScheduledTaskAgent", new TimeSpan(0, 0, 30));
throw new Exception("Bang");
#endif
NotifyComplete();
}
Run Code Online (Sandbox Code Playgroud)
这会导致后台任务在两次调用后在模拟器中的设置下关闭.但是,如果我重新打开应用程序调用ScheduledActionService.Find工作没有异常.我还可以删除失败的PeriodicTask并添加一个没有问题的新实例.
"在手机的设置中停用后台代理时可能会抛出异常.我认为在这种情况下会在ScheduledActionService.Add上抛出异常,而不是ScheduledActionService.Find"
我在模拟器中试过这个.我得到以下异常ScheduledActionService.Add(task);:
System.InvalidOperationException - "BNS错误:操作已禁用\ r \n"
调用ScheduledActionService.Find仍然可以正常工作.
我设法在模拟器和连接到我的 PC 的手机上重现 ArgumentException 和 StackTrace。
步骤是:
ScheduledActionService.Find(TASK_NAME)ScheduledActionService.LaunchForTest(TASK_NAME, new TimeSpan(0, 0, 1));在添加周期性任务后立即调用。SetupApplicationBar(),最终调用该ScheduledActionService.Find()方法。异常类型:ArgumentException
消息:E_INVALIDARG
堆栈跟踪:
在 Microsoft.Phone.Scheduler.SystemNotificationInterop.CheckHr(Int32 小时)
在 Microsoft.Phone.Scheduler.SystemNotificationInterop.GetNotificationByID(Guid notificationID)
在 Microsoft.Phone.Scheduler.ScheduledActionService.Find(字符串名称)
在 SolarCalculator.Agents.TaskIsActive()
在 SolarCalculator.MainPage.SetupApplicationBar()
在 SolarCalculator.MainPage.MainPage_Loaded(对象发送者,RotedEventArgs e)
在 MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex,委托 handlerDelegate,对象发送者,对象参数)
在 MS.Internal.JoltHelper.FireEvent (IntPtr 非托管Obj、IntPtr 非托管ObjArgs、Int32 argsTypeIndex、Int32 actualArgsTypeIndex、字符串事件名称)
鉴于应用程序正在关闭,我只是想弄清楚后台代理是否正在运行,我认为捕获异常并从我的TaskIsActive()方法返回 false 是安全的。
现在我知道来自 ArgumentException 的消息是 E_INVALIDARG,我发现在 Windows Phone 7 中设置警报,其中描述了在 Application_Exit 事件中调用 ScheduleActionService 时出现相同的错误。
| 归档时间: |
|
| 查看次数: |
1299 次 |
| 最近记录: |