31

I'm new to Win 8 Metro application development, and discovered that lots of things seem to be changed from the classic WPF.

What troubles me the most is that there's no way to close the app. This is extremely annoying when it comes to debugging the app. Therefore I'm looking at ways to add a "close" button in my app.

However, the old WPF way of:

Application.Current.Shutdown()

no longer exists. And I couldn't find the Process class in System.Diagnostics any more.

Does anyone know how to do this?

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Daqi Pei
  • 369
  • 3
  • 6
  • How about just pressing `Alt+F4`? – Gabe Jan 27 '12 at 02:53
  • @Gabe: No, `Alt+F4` won't close Metro apps (although I think it works with the development tools enabled/installed). Nor would it do it programmatically. :-) – Cody Gray - on strike Jan 27 '12 at 02:57
  • 2
    The lack of closing is by design - lifetime management is supposed to take care of resources, and "Close" button in the app is frowned upon as a matter of UI design. If you just need to close for debugging, have you considered using `taskkill`? You can create an icon for it on the desktop or taskbar, and then assign a shortcut key for convenience. – Pavel Minaev Jan 27 '12 at 03:13
  • 1
    @Pavel: It seems like a suboptimal design to force users to resort to some expert maneuver to deal with a misbehaving app. If an app can't close itself, Windows should provide a way to do so. – Gabe Jan 27 '12 at 03:37
  • Sounds similar to the iPhone/iPad design methodology. – Jason Down Jan 27 '12 at 03:42
  • Except that in iOS, it's easy to quit an application. No scary Task Manager required. – Cody Gray - on strike Jan 27 '12 at 03:58
  • At CES Microsoft showed a way for the user to close a Metro app, by swiping from top to bottom. – Tiago Andrade e Silva Jan 27 '12 at 09:15
  • 4
    Hehe, it's going to take a while to get Windows programmers used to the new ways. What exactly *is* the point of exiting a program? It will just take longer when I need it again. Clearly this should be an OS job and not a user annoyance. File + Save is long overdue to be excised as well. Etcetera. Sigh, I'm out of taskbar button space, gotta close something. – Hans Passant Jan 27 '12 at 13:30
  • 1
    You can think of metro apps as websites. You can't "kill" a website, can you? – Lukasz Madon Jan 27 '12 at 16:31
  • You know what I don't get... Practically everyone loves automation (hence the massive popularity of WSH and batch scripts, etc) - but the very second MS releases apps that can determine whether it should close or not (_for you_), we're all like "Oh FTS! I wanna close it myself!" lol - I think we all have control issues. I mean, we don't like it cause we're not closing it ourselves. But with automated batch scripts - we're still, in a way, closing it ourselves (by writing the script (probably a dumb scenario to use but whatevs)). – jay_t55 Jul 31 '13 at 07:50
  • @lukas, well yeah, you see, apps are inside windows. Websites are inside windows. When you click the X on the browser window, or on the corresponding tab - you are thereby effectively killing that website. lol. Btw, I'm just playing around - but it is true lol. – jay_t55 Aug 13 '13 at 09:32

6 Answers6

32

You're looking for App.Current.Exit()

Robert Levy
  • 28,747
  • 6
  • 62
  • 94
  • 1
    @OMA Do you find the way of closing apps on an iPad/iPhone more intuitive? (Press Home to leave app, double-press Home to open list of running apps, tap-hold the icon for your app until it starts to shake, then press the tiny red cross to close it.) – Tormod Fjeldskår Oct 03 '12 at 06:01
  • 2
    That's not better certainly, but at least it was a new system with this behaviour from the start. In the case of Windows 8, it has a legacy of versions where apps were closed just by pressing an X in the top right corner. Why don't keep that for metro apps? (specially when using a desktop PC!). That's easy and EVERYONE already knows that. Dragging the mouse from up to down to close an app is not very discoverable unless they show a tutorial the first time Windows 8 is run (and if they really have to do that, then it just shows how unintuitive the whole thing is). – OMA Oct 23 '12 at 05:03
4

The WinRT reference documentation for the developer preview states that:

CoreApplication.Exit | exit method

Shuts down the app.

Source: http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.core.coreapplication.exit.aspx

Tormod Fjeldskår
  • 5,952
  • 1
  • 29
  • 47
1

This is what I found to close the app.

  App.Current.Exit();
Norm
  • 11
  • 1
0

As far as I know you can't close a Metro app (by design) (using the Task-Manager is the only option that works) and as far as I know there is no way to exit a Metro app programatically (by design too).

You could try to throw an unhandled exception (I wouldn't recommend that).

Jay
  • 2,141
  • 6
  • 26
  • 37
-1

Try this.. It worked

App.Current.Terminate();
kleopatra
  • 51,061
  • 28
  • 99
  • 211
-3

I used crash code to exit Windows 8 Metro APP. char *p = nullptr; *p = 1;

Yigang Wu
  • 3,596
  • 5
  • 40
  • 54
  • Never crash an app to cause exit, it's really bad practice. Also, apps can now be withdrawn from the windows store if their crash count is too high. – Jon Rea Jan 08 '13 at 14:05