Mango Quick Tips: Background Agents Debugging

Weird Error

In attempting to add and test background agents for one of my applications I came across the following error:

BNS Error: The action’s start time has passed when trying to create/update the request

The error raised immediately after calling the ScheduledActionService.LaunchForTest method while debugging.  I’m not sure what that means but the error went away after restarting the emulator.  I can’t reproduce the error now so not sure if I was just in some weird state or what.

Wait for it …

The LaunchForTest method has ended up being really useful in testing my background agents.  Initially though, I didn’t think it was working.  I expected the agent to run at the specified TimeSpan.  Turns out its not quite that quick.   Even if I set the TimeSpan for 1 second it takes about 10-15 seconds for the agent to actually run.  This additional time seems to be constant across any TimeSpan.  So be patient when debugging agents. 

Another potential confusion point starts from the fact that if you add a breakpoint within the agent and debug your app it says the symbols haven’t been loaded.  

image

So I added a Toast notification to show me the agent ran but when debugging nothing happened.  So I thought it wasn’t working.  I kept troubleshooting and went to the settings page to see if my app’s background agent registered, it had and while I was there the Toast appeared then my breakpoint hit as well. 

After further testing, I found the Toast doesn’t appear while in the app and then I remembered that is by design.  You have to handle Toasts programmatically in your app, they will not display if your app is already running.

Regarding the breakpoint, the symbols must not be loaded until the agent actually runs but they will be loaded and the it will break.

So to summarize, if your trying to get quick feedback that your background agent is working you should:

  1. set the LaunchForTest TimeSpan to 1 second
  2. set a breakpoint within your agent
  3. wait 10-15 seconds

Happy Coding!

2 thoughts on “Mango Quick Tips: Background Agents Debugging”

Leave a Reply to rschiefer Cancel reply