Beware the sleeping emulator

There’s a great scene in an old Simpsons episode where Lisa is doing an experimentation for class where she shows how a hamster learns not to touch electrified food it wants but where Bart never learns..

That’s one of my favorite scenes (and yes, I could have quoted Einstein’s definition of Insanity: “Insanity: doing the same thing over and over again and expecting different results.”, but with all due respect to the theory of relatively, this is The Simpsons we are talking about here)

In any case, this one issue keeps biting me whenever I use the emulator and background tasks (agents). You’d expect me to realize what’s happening after the umpteenth time this happened, but every time it stumps me for a few minutes until I do the facepalm thing, remembering the issue.

If you are using the ScheduledActionService.LaunchForTest method to test your scheduled action, sometimes, it just won’t work – your Background task will just not run. The issue is easily solved by rebooting the emulator.

This (and some other clock related issues) happen because the Emulator, when waking up from sleep, loses synchronicity in it’s internal clock – right after sleep, some parts of the emulator will think that the time is the “now” of your computer while other parts of it will think that time “stopped” when you put your computer to sleep.

The workaround is super simple, but remembering that that may be the issue sometimes eludes me.

This entry was posted in Dev and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s