获取电脑的网络连接状态(五)WebClient
网络连接判断,使用WebClient测试获取:
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左右。
作者:唐宋元明清2188
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须在文章页面给出原文连接,否则保留追究法律责任的权利。