如果网络不可用,我想关闭我的应用。
我在App.cs
中检查网络:
private void Application_Launching(object sender, LaunchingEventArgs e)
{
if (!NetworkInterface.GetIsNetworkAvailable())
{
//close my app
}
else
{
//continue to work
}
}
有更好的方法吗?
提前致谢。
答案 0 :(得分: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.
答案 1 :(得分:1)
Application.Current.Terminate();