简体   繁体   English

如何以编程方式关闭Windows 8应用程序?

[英]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. 我正在为Windows 8构建应用程序,并且需要能够使用操作以编程方式关闭它。 For example, a button on my application. 例如,我的应用程序上的一个按钮。

I'm building my application using HTML5 我正在使用HTML5构建我的应用程序

The following event handler worked for me...I actually put an Exit icon in a global app bar...users love it! 以下事件处理程序对我有用......我实际上在一个全局应用程序栏中放了一个Exit图标......用户喜欢它!

        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) 上面的解决方案适用于C#...当在不支持触摸屏的机器上使用Windows 8商店应用程序时,它特别有用(我们的用户在模拟自上而下滑动以关闭应用程序时遇到困难...其他用户正在运行Windows 8在Mac VM上使Alt + F4变硬

You cannot. 你不能。 The Windows Runtime API (and the modern subset of the windows SDK) don't provide mechanisms to terminate applications. Windows运行时API(以及Windows SDK的现代子集)不提供终止应用程序的机制。

The model for Windows Runtime based applications is to allow the system or the user to manage the process lifetime. 基于Windows运行时的应用程序的模型是允许系统或用户管理进程生命周期。

在JS中你可以这样做:

window.close();

您无法以编程方式关闭应用程序,这是系统的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM