如何在c#webbrowser控件中检查连接

如何在c#webbrowser控件中检查连接,c#,webbrowser-control,C#,Webbrowser Control,我编写了简单的web浏览器代码,希望在连接不可用时显示消息。我使用了“try catch”,但它不起作用。我如何检测我的网络连接是否可用 Ping一个几乎像4.2.2.4,4.2.2.3,4.2.2.2一样高的DNS Ping myPing = new Ping(); String host = "4.2.2.4; byte[] buffer = new byte[32]; int timeout = 1000; PingOptions pingOptions = new PingOptions

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

Ping一个几乎像4.2.2.4,4.2.2.3,4.2.2.2一样高的DNS

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