获取电脑的网络连接状态(三)Ping

时间:2020-05-27 15:48:17   收藏:0   阅读:96

网络连接判断,使用ping测试获取:

 1     private static async Task<bool> IsPingSuccess()
 2     {
 3         try
 4         {
 5             using (Ping myPing = new Ping())
 6             {
 7                 var result = await myPing.SendPingAsync("google.com", 3000 /*3 secs timeout*/, new byte[32], new PingOptions(64, true));
 8                 return result.Status == IPStatus.Success;
 9             }
10         }
11         catch
12         {
13             // ignored
14         }
15         return false;
16     }

ping获取网络状态的耗时,一般在几十ms,延时性偏高

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!