用SendAsync ping很多IP会返回超时问题

时间:2018-10-11 19:18:11

标签: vb.net

标题。我使用SendAsync对200个不同的IP进行ping操作,其中一些返回超时0 ping,即使我仅对它们进行ping操作,它们也会返回成功的ping。即使仅使用1个IP进行200次ping,Single问题仍然存在。我试图将a)数组长度b)Ping Options更改为其他数字和True。什么都没做。我不知所措。

Dim array() As Byte = System.Text.ASCIIEncoding.ASCII.GetBytes("aaaaaaaaaaaaaaaaaaaaa")
Dim obj As New Object
dim list As new list(of string)

Sub DoWork()
    For Each item In list
        PingSubroutine(item)
    Next
End Sub
    Sub PingSubroutine(ByVal str As String)
        Dim p As Ping = New Ping
        AddHandler p.PingCompleted, AddressOf PingResult
        p.SendAsync(str, 10000, array, New PingOptions(600, False), str)
    End Sub

    Sub PingResult(ByVal sender As Object, ByVal e As System.Net.NetworkInformation.PingCompletedEventArgs)
        Invoke(Sub()
                   SyncLock (obj)
                       RichTextBox1.AppendText(e.UserState.ToString + " -> " + e.Reply.RoundtripTime.ToString + vbNewLine)
                   End SyncLock
               End Sub)
    End Sub

0 个答案:

没有答案