title: How can I simulate my Metro app being terminated?
body: <p>VS2012's default C# "Metro style" project templates include code in App.xaml.cs (in the <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.application.onlaunched.aspx" rel="noreferrer"><code>OnLaunched</code></a> override) to restore the application state after a suspend-and-terminate. This code only runs when <a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.applicationmodel.activation.launchactivatedeventargs.previousexecutionstate.aspx" rel="noreferrer"><code>LaunchActivatedEventArgs.PreviousExecutionState</code></a> is <a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.applicationmodel.activation.applicationexecutionstate.aspx" rel="noreferrer"><code>Terminated</code></a>, i.e., "The app was terminated after being suspended."</p>
  
  <p>How can I force my app to be suspended and terminated, so I can test this suspend/resume functionality in my app?</p>
  
  <p>Things I've tried that don't work:</p>
  
  <ul>
  <li>If I use the "close app" gesture (drag from the top of the screen to the bottom), then the next run's <code>PreviousExecutionState</code> is <code>ClosedByUser</code>.</li>
  <li>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 <code>PreviousExecutionState</code> is <code>NotRunning</code>. 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".</li>
  <li>You'd <em>think</em> 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.)</li>
  </ul>
  
  <p>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.</p>
  
  <p>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?</p>