Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I simulate my Metro app being terminated?

VS2012's default C# "Metro style" project templates include code in App.xaml.cs (in the OnLaunched override) to restore the application state after a suspend-and-terminate. This code only runs when LaunchActivatedEventArgs.PreviousExecutionState is Terminated, i.e., "The app was terminated after being suspended."

How can I force my app to be suspended and terminated, so I can test this suspend/resume functionality in my app?

Things I've tried that don't work:

  • If I use the "close app" gesture (drag from the top of the screen to the bottom), then the next run's PreviousExecutionState is ClosedByUser.
  • If I kill the app -- either using Task Manager, or (if I was debugging) with the "stop" button on the VS toolbar -- then the next run's PreviousExecutionState is NotRunning. This is true even if Task Manager showed the app as "Suspended" before I ended task, so clearly it's more nuanced than the description of "terminated after being suspended".
  • You'd think I could just switch away from my app, and then open lots of other Metro-style apps until my app eventually gets kicked out. But even if I open every single Metro-style app that ships with the Windows 8 Release Preview, that's apparently not enough memory pressure to make Windows terminate my app. (I assume Windows would be less likely to terminate an app that was being debugged, so I launched my app from the Start screen -- no debugger -- before I tried this.)

It does appear that, if I switch away from my app and type into a StackOverflow window for several minutes, that my app will eventually get terminated, so perhaps there's a time-based component to it. But if I have to wait five or ten minutes every time for my app to terminate, that's a pretty slow testing cycle.

Given that this is something developers will have to test, you'd think there would be a nice, easy way for a dev to force an app to suspend-and-terminate. Is there some kind of stress-test app that comes with Visual Studio that will force enough memory pressure? Is there some menu item in Visual Studio that will force termination of my app? How are we supposed to test this?

like image 303
Joe White Avatar asked Jun 24 '12 17:06

Joe White


People also ask

How to terminate app in iOS simulator?

First press Shift+Command+ H twice. This will open up all the apps that are currently open. Swipe left/right to the app you actually want to close. Just Swipe Up using the Touchpad while Holding the App would close the app.

How do you shake Iphone simulator?

In the Hardware menu, choose Shake Gesture. That's it. Your shake handler should be called when you do so.


3 Answers

In Visual Studio 2012, when you're debugging, there are "Suspend", "Resume" and "Suspend and Shutdown" buttons. By default, you should see the buttons while you are debugging your app. See this article for more info on debugging process lifecycle.

enter image description here

like image 178
JP Alioto Avatar answered Sep 24 '22 06:09

JP Alioto


I had trouble finding the Suspend control because VS wasn't showing a second row of toolbars for me. As it turns out, this is on the "Debug Location" toolbar. Make sure you have this toolbar turned on and then you should be able to find the Suspend control (and it does work to solve the OP's problem).

like image 6
Paul McKee Avatar answered Sep 20 '22 06:09

Paul McKee


If they don't show by default, go to TOOLS -> CUSTOMIZE, and under the Toolbars tab, check the box that says "Debug Location"

like image 3
Roman Jaquez Avatar answered Sep 20 '22 06:09

Roman Jaquez