【问题标题】:How to check connection in c# webbrowser control [duplicate]如何在c# webbrowser控件中检查连接[重复]
【发布时间】:2013-07-05 15:37:46
【问题描述】:

我编写了简单的网络浏览器代码,我想在连接不可用时显示消息。我使用“try catch”但它不起作用。我如何检测我的网络连接是否可用。

【问题讨论】:

  • 但它不起作用意味着什么?请更具体

标签: c# webbrowser-control


【解决方案1】:

Ping 一个几乎启动的 DNS 像 4.2.2.4,4.2.2.3,4.2.2.2

Ping myPing = new Ping();
String host = "4.2.2.4;
byte[] buffer = new byte[32];
int timeout = 1000;
PingOptions pingOptions = new PingOptions();
PingReply reply = myPing.Send(host, timeout, buffer, pingOptions);
if (reply.Status == IPStatus.Success {
  // presumably online
}

【讨论】:

  • 以上代码在线和离线都返回true
猜你喜欢
  • 1970-01-01
  • 2012-07-11
  • 2010-11-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-18
  • 2018-05-05
  • 1970-01-01
相关资源
最近更新 更多