Как проверить доступность интернет-соединения в ОС Windows 8, С#? Я посмотрел MSDN, но страница была удалена.
Проверьте подключение к Интернету (доступность) в Windows 8
Ответ 1
Я использую этот фрагмент без проблем:
public static bool IsInternet()
{
ConnectionProfile connections = NetworkInformation.GetInternetConnectionProfile();
bool internet = connections != null && connections.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess;
return internet;
}
Ответ 2
Мне пришлось использовать 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;
}
}
Ответ 3
Для Windows Phone Следующий код может быть полезным:
var networkInformation = NetworkInformation.GetConnectionProfiles();
if (networkInformation.Count == 0)
{
//no network connection
}