码迷,mamicode.com
首页 > Web开发 > 详细

获取电脑的网络连接状态(五)WebClient

时间:2020-05-27 15:26:53      阅读:71      评论:0      收藏:0      [点我收藏+]

标签:return   ntc   connected   als   电脑   nec   bool   使用   延时   

网络连接判断,使用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左右。

获取电脑的网络连接状态(五)WebClient

标签:return   ntc   connected   als   电脑   nec   bool   使用   延时   

原文地址:https://www.cnblogs.com/kybs0/p/12972859.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!