我有以下方法:
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/