I’ve been developing an app for Windows 8 and can test Suspend, Resume, Shutdown, etc. from Visual Studio 2012. However, when I test the app on a Microsoft Surface, there is one other state I can’t seem to simulate.
When an app is open and you leave the Surface untouched for a bit, the screen will dim and then eventually shut-off. If I wait long enough, maybe 1 or 2 minutes, and hit the start button, it will take me to the Lock Screen, where I can sign in. Once I sign in, it will show my app where I left it. However, after 1 second, it crashes immediately, and the Surface takes me back to the Start Screen.
I cannot simulate this using Visual Studio and the Simulator. Suspending/Resuming using Debug Location does not recreate this.
I looked at the event log on the Surface and found that my app was crashing with the following:
The process was terminated due to an unhandled exception.
Exception Info: System.Exception Stack: at
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at
System.Threading.WinRTSynchronizationContext+Invoker.<InvokeCore>b__0(System.Object) at
System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(System.Object) at
System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) at
System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) at
System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() at System.Threading.ThreadPoolWorkQueue.Dispatch() at
System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
I have no clue how to find this. I am handling all unhandled exceptions with a standard message box, but it’s not showing up. We’ve been very good at avoiding “async void” and making sure everything has “async Task” and awaited properly. So, I’m a bit stuck. I can’t find where this is happening.
Anyone know how I can simulate this, or at least make the Event Log more verbose?
Ok I figured it out.
There is an issue with the
MediaElementcontrol and volume. When the app is reactivated as I explain above, we get notified that the volume has changed. But for some reason, if we try to manipulateMediaElement.Volumewhen the app reactivates, it throws an exception. This exception does not have a message, just some strange hex number.This only happens on the tablet, and it’s very hard to detect. Essentially, for all of you who play media files, you should try/catch it like this:
Anyway, thank you @JerryNixon and @chuex for helping out.