1

如果网络不可用,我想关闭我的应用程序。

我检查网络App.cs

private void Application_Launching(object sender, LaunchingEventArgs e)
        {
            if (!NetworkInterface.GetIsNetworkAvailable())
            {
                //close my app
            }
            else
            {
                 //continue to work
            }
        }

有更好的方法吗?

提前致谢。

4

2 回答 2

1

只需添加对Microsoft.Xna.Framework.Game我确定您可以使用此代码实现退出的引用,就可以了。如果您想显示消息框,您必须在主页中进行

我会做什么:

protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (!NetworkInterface.GetIsNetworkAvailable())
            {
               MessageBoxResult m = MessageBox.Show(Sorry, no internet connection is available.do you want to exit the application , "Oops...", MessageBoxButton.OKCancel);
                if (m == MessageBoxResult.OK)
                {
                    var g = new Microsoft.Xna.Framework.Game();
                        g.Exit();
                }
            }           
        }

您应该提供一种“温和”的关闭方式

5.1.2 - 应用关闭

The app must handle exceptions raised by the any of the managed or native System API 
and not close unexpectedly. During the certification process, the app is monitored 
for unexpected closure. An app that closes unexpectedly fails certification. The app
must continue to run and remain responsive to user input after the exception is
handled.

欲了解更多信息,请访问此链接

于 2013-05-22T06:59:53.403 回答
1
Application.Current.Terminate();
于 2013-05-22T07:00:42.600 回答