I have a Windows Phone 7 app deployed in the marketplace that updates its Live Tile via a PeriodicTask Background Agent.
One user is reporting issues with the tile no longer updating after it has been working for some time.
When they check the background tasks on the phone it is disabled and the checkbox to "Turn background tasks back on for this application the next time I open it" is checked.
After opening the app and trying the pin operation again the background task hasn't resumed.
I suspect this may be related to two crash reports I've seen in the App Hub:
Problem Function: Microsoft.Phone.Scheduler.SystemNotificationInterop.CheckHr
Exception Type: ArgumentException
Stack Trace:
Frame Image Function Offset
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
Calls to Microsoft.Phone.Scheduler.ScheduledActionService.Find are resulting in an ArgumentException.
The name parameter I am calling the Find method with is coming from a private const string
so the value will be the same with each call.
Should I just catch this exception and assume the background agent isn't present or is it indicating something is wrong with the agent?
At this stage I can't reproduce the exception when running the app in the emulator.
"When [the] Background Agent crashes two times in sequence, it's removed from scheduling"
I've tried deliberately crashing the ScheduledAgent on every invocation as follows:
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();
}
This does cause the background task to turn off under the settings in the emulator after two invocations. However, if I reopen the app calls to ScheduledActionService.Find work without an exception. I can also remove the failed PeriodicTask and add a new instance without issue.
"an exception can be thrown when the background agent is deactivated in the phone's settings. I think in that case the exception is thrown on ScheduledActionService.Add, not ScheduledActionService.Find"
I tried this in the emulator. I get the following exception from ScheduledActionService.Add(task);
:
System.InvalidOperationException - "BNS Error: The action is disabled\r\n"
Calls to ScheduledActionService.Find still work fine.