2

I'm writing my first Windows Store app (windows 8.1) and I notice that when I run it in debug mode, and I close the app (by clicking the x in the top right, or by dragging from the top of the screen to the bottom), it is still running in Visual Studio. My first question is, is this a problem? It seems like it's a problem.

I started from a template, I'm not doing anything with threads, and there is only one page (MainPage.xaml) at the moment. I have looked at questions which seem similar, in particular this one: WPF App Doesn't Shut Down When Closing Main Window but I am unable to get their suggestions to work.

When I add ShutdownMode="OnExplicitShutdown" to my app.xaml, I get these errors in my Error List:

  • The member "ShutdownMode" is not recognized or is not accessible.
  • The property 'ShutdownMode' was not found in type 'Application'.

Also I notice that there is no StartupUri specified, nor can I add one (same errors as above.)

The other suggestion was to override OnClosed in MainWindow.xaml.cs and close the application there. I have no MainWindow.xaml.cs; I have MainPage.xaml.cs instead, and it does not have an OnClosed.

The Application class is of type Windows.UI.Xaml.Application.

If I pause VS after closing the app, it takes me to this (generated) code:

#if !DISABLE_XAML_GENERATED_MAIN
public static class Program
{
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Windows.UI.Xaml.Build.Tasks"," 4.0.0.0")]
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    static void Main(string[] args)
    {
        global::Windows.UI.Xaml.Application.Start((p) => new App()); //<==here
    }
}
#endif

Can anyone tell me what's going on?

Community
  • 1
  • 1
Mishelle
  • 382
  • 1
  • 3
  • 11

1 Answers1

4

This is entirely normal, the debugger tells you what is really going on. All Modern UI apps work this way. Just check it out with Task Manager, Details tab. Observe how dismissing the window doesn't terminate the process, it just suspends it.

You don't just have a modern UI, you have modern operating system behavior as well. A user doesn't have enough information available to judge if terminating a process is actually useful. If the machine has plenty of resources then there isn't any point. Better to keep the process running so that when the user starts it again, it instantly wakes up. Which is nice, users like that.

Conversely, if the OS requires resources for another process and not enough are available than it will automatically terminate a process without the user's assistance. The life-cycle for Modern UI apps supports this. Nothing particularly revolutionary btw, mobile operating systems like Android do this as well. Also the way I use my desktop apps these days, I just leave them running. Until I run out of taskbar space, cleanup then. Annoying :)

Truly stopping the process is easy, just click the Red Button on the VS toolbar.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Ah. So you're saying there's no way to shut it down explicitly, but that's by design and I shouldn't worry about it. Thanks! – Mishelle Feb 07 '15 at 18:47