1 public static bool IsWebClientConnected()
2 {
3 try
4 {
5 using (var client = new WebClient())
6 using (var stream = client.OpenRead("http://www.qq.com"))
7 {
8 return true;
9 }
10 }
11 catch
12 {
13 return false;
14 }
15 }
直接访问web地址来测试网络的可用性,这个方法延时超高,不建议使用。首次判断100ms-150ms,后续基本维持在20-40ms左右。