您的位置:首页 > 理论基础 > 计算机网络

wp7检测网络是否可用以及网络开启简单代码段

2013-01-21 15:52 477 查看
private bool networkIsAvailable;

networkIsAvailable = Microsoft.Phone.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable();//当前网络是否可用
if (!networkIsAvailable)
{
Dispatcher.BeginInvoke(() =>
{
MessageBoxResult res = MessageBox.Show("OK and Cancel", "您没有开启网络或者信号不好!,如需设置网络请选择“OK”", MessageBoxButton.OKCancel);
if (res == MessageBoxResult.OK)
{
ConnectionSettingsTask connectionSettings = new ConnectionSettingsTask();
//将连接设置更改为飞行模式
connectionSettings.ConnectionSettingsType = ConnectionSettingsType.Cellular;
connectionSettings.Show();
}
else
return;
});
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: