C#中如何处理ping异常?
我收到以下代码的错误 System.Net.NetworkInformation.PingException
。
Ping ping = new Ping();
PingReply stats = ping.Send(IPAddress.Parse("8.8.4.4"));
if (stats.Status == IPStatus.Success)
{
if(net)
textBox1.Text = "connected";
else
textBox1.Text="Not connected";
}
有人能告诉我这里出了什么问题吗?
注意:错误发生在第 2 行
I am getting the error System.Net.NetworkInformation.PingException
for the following code.
Ping ping = new Ping();
PingReply stats = ping.Send(IPAddress.Parse("8.8.4.4"));
if (stats.Status == IPStatus.Success)
{
if(net)
textBox1.Text = "connected";
else
textBox1.Text="Not connected";
}
Can anybody tell whats wrong here?
NOTE : the error occurs on line 2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要处理异常,请将代码插入到 try catch 语句中,如下所示:
To handle exceptions insert your code in a try catch statement like this:
根据
Ping.Send
文档:因此,您需要对其进行调试并检查内部异常值以找出原因。我们无法为您做到这一点。
Per the documentation for
Ping.Send
:So, you need to debug this and inspect the inner exception value to find out why. We can't do that for you.