检查Windows 8中的Internet连接(可用性)

如何检查Windows 8中的Internet连接可用性,C#开发? 我查看了MSDN,但页面已被删除。

我使用这个片段没有问题:

public static bool IsInternet() { ConnectionProfile connections = NetworkInformation.GetInternetConnectionProfile(); bool internet = connections != null && connections.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess; return internet; } 

我不得不使用GetConnectionProfiles()和GetInternetConnectionProfile()使其在所有设备上运行。

 class ConnectivityUtil { internal static bool HasInternetConnection() { var connections = NetworkInformation.GetConnectionProfiles().ToList(); connections.Add(NetworkInformation.GetInternetConnectionProfile()); foreach (var connection in connections) { if (connection == null) continue; if (connection.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess) return true; } return false; } } 

对于Windows Phone以下代码可能有用:

 var networkInformation = NetworkInformation.GetConnectionProfiles(); if (networkInformation.Count == 0) { //no network connection }