Ahmed Ali
Ahmed Ali

Reputation: 2668

How to close a Windows 8 application programmatically?

I'm building an application for Windows 8 and need to be able to close it programmatically using an action. For example, a button on my application.

I'm building my application using HTML5

Upvotes: 2

Views: 2579

Answers (4)

Brianswer
Brianswer

Reputation: 354

In JS you can do this:

window.close();

Upvotes: 3

iTrout
iTrout

Reputation: 1454

The following event handler worked for me...I actually put an Exit icon in a global app bar...users love it!

        private void closeButton_Click(object sender, RoutedEventArgs e)
        {
            App.Current.Exit();
        }

Good Luck!

This solution above works for C#...it's especially helpful when using Windows 8 Store Apps on machines that are not touch screen capable (our users were having difficulty emulating the top down swipe to close an app...other users are running a Windows 8 on a Mac VM which makes the Alt + F4 tough)

Upvotes: 9

Mahmoud
Mahmoud

Reputation: 1182

You can't close an app programmatically, it's the system's choice.

Upvotes: 1

Larry Osterman
Larry Osterman

Reputation: 16142

You cannot. The Windows Runtime API (and the modern subset of the windows SDK) don't provide mechanisms to terminate applications.

The model for Windows Runtime based applications is to allow the system or the user to manage the process lifetime.

Upvotes: 3

Related Questions