芮源:
public class IsInternet
{
/// <summary>
/// 判断是否有网
/// </summary>
/// <returns>true为有网,false为无网</returns>
public bool IsInternetAvailable()
{
try
{
Dns.GetHostEntry("www.google.com"); //using System.Net;
return true;
}
catch (SocketException ex)
{
return false;
}
}
}
芮源:
IsInternet ty = new IsInternet();
芮源:
if (ty.IsInternetAvailable()) return;