15

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?

Joe White
  • 94,807
  • 60
  • 220
  • 330
  • If you still want to test the behaviour of the application being "kicked out", you could always create 3 or 4 hello world apps that allocate "enough memory" to get your system low on resources. – yms Jun 28 '12 at 18:16

4 Answers4

27

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

JP Alioto
  • 44,864
  • 6
  • 88
  • 112
  • 1
    I can't believe how many times I looked at that and didn't see it. It was on the *second row* of toolbars, and for some reason my eye kept skipping right past that entire second row, even with your screenshot to go from. Guess that's the downside of the new "chromeless" look: no visual cues to suggest there's more to look at. – Joe White Jun 25 '12 at 11:52
  • @JoeWhite Agree ... I'm slowly learning the new interface as well. It takes time to find button that I knew exactly where they were before. :) – JP Alioto Jun 25 '12 at 15:56
  • 7
    For those who wonder how to display this toolbar, go to View -> Toolbar -> Debug Location. – Ucodia Dec 21 '12 at 01:29
6

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).

Paul McKee
  • 61
  • 1
3

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

Roman Jaquez
  • 2,499
  • 1
  • 14
  • 7