gkellogg
New member
I am in the process of making a program that does continuous pings on a target. Basically it pings the target and returns back a response (Successful, host unreachable, etc) which is then added to a listbox. So far The program crashes if I attempt to put the code in a Do Loop. Based on this I then proceeded to add in a control feature to limit the number of loops (I set it to 10). This does not crash the application, but the responses are added too quickly to the listbox. Is there a way to slow down the loop so that each items.add into the list box are maybe 1-2 seconds apart? I have tried using thread.sleep but it pauses before anything is added to the listbox, then adds all 10 items. Here is my source code.
Private Sub ping()
Dim i As Integer
Do Until i = 10
Dim LongIP As UInt32
Dim Buffer As String
Dim hIP As Integer
Dim timeout As Short
Buffer = Space(32)
LongIP = convertIPtoLong((tbIP.Text))
hIP = IcmpCreateFile()
pIPo.TTL = 255
timeout = 2000
IcmpSendEcho(hIP, LongIP, Buffer, Len(Buffer), pIPo, pIPe, Len(pIPe) + 8, timeout)
Dim response = describeResponse(pIPe.status).ToString()
ListBox1.Items.Add(response)
Thread.Sleep(500)
i = i + 1
Loop
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If tbIP.Text = "" Then
MsgBox("Please Enter an IP Address")
Else
ping()
End If
End Sub
Private Sub ping()
Dim i As Integer
Do Until i = 10
Dim LongIP As UInt32
Dim Buffer As String
Dim hIP As Integer
Dim timeout As Short
Buffer = Space(32)
LongIP = convertIPtoLong((tbIP.Text))
hIP = IcmpCreateFile()
pIPo.TTL = 255
timeout = 2000
IcmpSendEcho(hIP, LongIP, Buffer, Len(Buffer), pIPo, pIPe, Len(pIPe) + 8, timeout)
Dim response = describeResponse(pIPe.status).ToString()
ListBox1.Items.Add(response)
Thread.Sleep(500)
i = i + 1
Loop
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If tbIP.Text = "" Then
MsgBox("Please Enter an IP Address")
Else
ping()
End If
End Sub