获取电脑的网络连接状态(五)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左右。

posted @ 2020-05-27 14:42  唐宋元明清2188  阅读(382)  评论(0编辑  收藏  举报