我使用以下代码在应用程序启动时检查网络访问
public async void CheckNetwork()
{
if (!NetworkAvailabilty.Instance.IsNetworkAvailable)
{
MessageDialog Message = new MessageDialog("Network access not available.", "Network Error");
Message.Commands.Add(new UICommand("Close"));
await Message.ShowAsync();
Application.Current.Exit();
}
}
这在 Windows 10 桌面中按预期工作。但是当我在手机中运行该应用程序时,它无法关闭该应用程序。这可能是什么原因以及如何强制关闭我的应用程序?
最佳答案
作为设计原则,您不应该手动关闭应用程序。请引用this link (针对 WP8 开发人员,但仍然有效)。 但是,如果您正在为自己开发测试应用程序,则可以抛出异常,这是关闭应用程序的唯一方法。
throw new Exception();
如果您打算在市场上发布您的应用,请不要这样做:
An unhandled exception in your app consumes resources unnecessarily both on the user’s phone and on the Windows Phone servers. The phone generates and uploads crash dumps for unhandled exceptions to help you find and fix bugs in your code. Crashing your app to close it wastes the user’s battery power and network bandwidth.
关于c# - 以编程方式关闭 Windows Phone 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34882812/