c# - 如何通过 3G 连接检查互联网连接状态?

标签 c# windows-8 microsoft-metro windows-runtime

我有以下方法:

public static bool IsNetworkConnected()
{
    ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();
    IReadOnlyList<ConnectionProfile> connectionProfile = NetworkInformation.GetConnectionProfiles();
    if (InternetConnectionProfile == null)
        return false;
    else
        return true;
}

当我以典型方式(通过 LAN 电缆或 Wi-Fi)连接到互联网时,它工作正常。当我使用我的 3G USB 调制解调器时,它返回 false(InternectConnectionProfile 为空)。这是为什么?我该如何解决?

最佳答案

您可以考虑对 Internet 上的服务器执行 ping 操作。这不是您问题的 100% 答案,但从不同的角度来看可能会有所帮助。

using System.Net;
using System.Net.NetworkInformation;

using (Ping Packet = new Ping()) 
{
    if (Packet.Send(IPAddress.Parse(IP), 1000, new byte[] { 0 }).Status ==   IPStatus.Success))
    {
       // ...
    }
}

关于c# - 如何通过 3G 连接检查互联网连接状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11757111/

相关文章:

windows-8 - 我们如何在服务器端验证 Windows 8 应用内账单收据?

c# - 在代码隐藏中控制 ScrollViewer 的缩放功能

c# - Windows 8 中的动态磁贴是如何制作的?

javascript - 在 Javascript Windows 应用商店应用程序中加载许多音频文件

c# - 无法将类型 IAsyncOperation<StorageFile> 隐式转换为 StorageFile

使用字符串数组的 IN 语句的 C# Dapper 问题

c# - 提取 XML 标签值

c# - 在 WPF 中使用 Oxyplot 进行数据绑定(bind)

c# - webBrowser 控件停止来自网站的 javascript 警报

c# - Windows 8 应用程序和访问文件系统