我有以下方法:
public static bool IsNetworkConnected()
{
ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();
IReadOnlyList<ConnectionProfile> connectionProfile = NetworkInformation.GetConnectionProfiles();
if (InternetConnectionProfile == null)
return false;
else
return true;
}
通过局域网电缆或无线网络连接 - 当我连接到互联网,在一个典型的方式,它工作正常。 当我用我的3G USB调制解调器返回false( InternectConnectionProfile
为空)。 这是为什么? 我怎样才能解决这个问题?
您可以考虑在互联网上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))
{
// ...
}
}
尝试
public static bool IsConnectedToInternet()
{
ConnectionProfile connectionProfile = NetworkInformation.GetInternetConnectionProfile();
return (connectionProfile!=null && connectionProfile.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess);
}
这可以帮助你http://social.msdn.microsoft.com/Forums/en-US/winappswithhtml5/thread/a7ba014c-3a31-4ff3-ba10-0c835305828b/