我有一个完全正常工作的ping代码,但我发现,如果ping返回时间很长,它将被标记为脱机。
代码:
Try
If BackgroundWorker1.CancellationPending Then
Exit Sub
End If
If My.Computer.Network.Ping(PRIBox.Text) Then
'Online
If GetPingMs(PRIBox.Text) < 125 Then
'Good ping
PRIPingIcon.Image = My.Resources.PingUP
Else
'Bad ping
PRIPingIcon.Image = My.Resources.PingHIGH
End If
Else
PRIPingIcon.Image = My.Resources.PingDOWN
'Offline
End If
Catch
End Try
在使用此功能的情况下,有没有超时,等于1500毫秒,或类似的东西?
我用于长往返
的附加功能Public Function GetPingMs(ByVal address As String) As Long
Dim ping As New System.Net.NetworkInformation.Ping
Return ping.Send(address).RoundtripTime
End Function
答案 0 :(得分:0)
想出来,抱歉浪费你所有的时间!
Try
If BackgroundWorker1.CancellationPending Then
Exit Sub
End If
If My.Computer.Network.Ping(PRIBox.Text, 1500) Then '<----
'Online
If GetPingMs(PRIBox.Text) < 125 Then
'Good ping
PRIPingIcon.Image = My.Resources.PingUP
Else
'Bad ping
PRIPingIcon.Image = My.Resources.PingHIGH
End If
Else
PRIPingIcon.Image = My.Resources.PingDOWN
'Offline
End If
Catch
End Try