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

相关文章:

  • 2022-12-23
  • 2021-10-12
  • 2021-12-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-10
猜你喜欢
  • 2021-09-02
  • 2021-10-18
  • 2022-02-14
  • 2021-10-24
  • 2022-02-11
  • 2021-11-12
  • 2022-12-23
相关资源
相似解决方案