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.
I managed to reproduce the ArgumentException and StackTrace in the emulator and on a handset attached to my PC.
The steps were:
ScheduledActionService.Find(TASK_NAME)
ScheduledActionService.LaunchForTest(TASK_NAME, new TimeSpan(0, 0, 1));
immediately after adding the PeriodicTask.SetupApplicationBar()
, which ultimately calls the ScheduledActionService.Find()
method.Exception Type: ArgumentException
Message: E_INVALIDARG
StackTrace:
at Microsoft.Phone.Scheduler.SystemNotificationInterop.CheckHr(Int32 hr)
at Microsoft.Phone.Scheduler.SystemNotificationInterop.GetNotificationByID(Guid notificationID)
at Microsoft.Phone.Scheduler.ScheduledActionService.Find(String name)
at SolarCalculator.Agents.TaskIsActive()
at SolarCalculator.MainPage.SetupApplicationBar()
at SolarCalculator.MainPage.MainPage_Loaded(Object sender, RoutedEventArgs e)
at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)
Given that the app is shutting down and I'm only trying to figure out if the background agent is running I figure it is safe to catch the exception and return false from my TaskIsActive()
method.
Now that I know the message from the ArgumentException is E_INVALIDARG I found Setting alarm in Windows Phone 7 which describes getting the same error when making calls to ScheduleActionService in the Application_Exit event.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With