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

时间:2013-07-05 15:37:46

标签: c# webbrowser-control

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

1 个答案:

答案 0 :(得分:0)

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
}