Wait for a function to run and then continue (ping)

  • Thread starter Thread starter Deepak
  • Start date Start date
D

Deepak

I am programing a ping application which pings various centers . I
used timer loop and it pings one by one.

Now when i finish pinging one center it should wait for the
ping_completed function to be executed and then continue pinging
another certer.

The ping_completed function is called on completion of ping by the os
and i have no control on it .

Wait for a function to run and then continue.


(the ping application is developed from the msdn samples)
 
I am programing a ping application which pings various centers . I
used timer loop and it pings one by one.

Now when i finish pinging one center it should wait for the
ping_completed function to be executed and then continue pinging
another certer.

So you'll like to block the ping function?
 
So you'll like to block the ping function?

no i dont want to block it . the ping completed function runs by
itself after some time.
i want to make it wait until the ping completed function runs and then
continue pinging another center.
 
no i dont want to block it . the ping completed function runs by
itself after some time.
i want to make it wait until the ping completed function runs and then
continue pinging another center.

If you want to make Ping "wait" then you're block the thread?

Do you want multi-threading (i.e. multiple pings at once) or do you want to
ping the centers one at a time (single threaded - blocking?).
 
If you want to make Ping "wait" then you're block the thread?

Do you want or do you want to
ping the centers one at a time

Sorry to reply late ,
ping the centers one at a time (single threaded - blocking?). as u
say. I don't know much about threading
here are the functions used
1 ) the ping completed one
Private Sub pingClient_PingCompleted( ByVal sender As Object,
ByVal e As PingCompletedEventArgs) _
Handles pingClient.PingCompleted
' Check to see if an error occurred. If no error, then
display the
' address used and the ping time in milliseconds
2 ) Private Sub sendPingButton_Click( ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
sendPingButton.Click
'it contains a loop with this command
pingClient.SendAsync(address1.Text, Nothing)
there are many text boxes (address2, address3,etc)

Now when the loop starts the first address is pinged . before the ping
completed is called for the first address the second address gets
pinged
I want it to wait till the ping completed function gets called and
then ping the second address.
 
Deepak said:
I am programing a ping application which pings various centers . I
used timer loop and it pings one by one.

Now when i finish pinging one center it should wait for the
ping_completed function to be executed and then continue pinging
another certer.

The ping_completed function is called on completion of ping by the os
and i have no control on it .

Wait for a function to run and then continue.

and then added:
1 ) the ping completed one
Private Sub pingClient_PingCompleted( ByVal sender As Object,
ByVal e As PingCompletedEventArgs) _
Handles pingClient.PingCompleted
' Check to see if an error occurred. If no error, then
display the
' address used and the ping time in milliseconds
2 ) Private Sub sendPingButton_Click( ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
sendPingButton.Click
'it contains a loop with this command
pingClient.SendAsync(address1.Text, Nothing)
there are many text boxes (address2, address3,etc)

Now when the loop starts the first address is pinged . before the ping
completed is called for the first address the second address gets
pinged
I want it to wait till the ping completed function gets called and
then ping the second address.

Instead of calling SendAsync from inside the button click handler, I'd
suggest you use a separate method, so you could call it from the
PingCompleted event handler as well. At each call, the method would
retrieve the next address in line from a global list and ping it.
Something in the lines of:

<aircode>
Private mPingsPending As New Queue(Of String)

Private Sub PingNext
If mPingsPending.Count = 0 Then
'... finished pinging.
'restore the UI, or whatever
Else
Dim Address As String = mPingsPending.Dequeue
PingClient.SendAsync(Address, Nothing)
End If
End Sub

Private Sub SendPingButton_Click( _
... _
) Handles SendPingButton.Click
'... 1) Get all addresses from wherever they are
'... 2) Add each address to mPingsPending:
'... mPingsPending.Enqueue(Address)
'... 3) Disable the UI, or whatever
'... 4) Ping'em!

PingNext
End Sub

Private Sub pingClient_PingCompleted( _
... ) Handles pingClient.PingCompleted
' Check to see if an error occurred. If no error, then
'display the address used and the ping time in
'milliseconds

'Continue pinging:
PingNext
End Sub

</aircode>

HTH.

Regards,

Branco.
 
Back
Top