By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,679 Members | 2,036 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,679 IT Pros & Developers. It's quick & easy.

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

P: n/a
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)

Feb 11 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"Deepak" <de*********@gmail.comwrote in news:1171221409.321605.259670
@a34g2000cwb.googlegroups.com:
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?
Feb 11 '07 #2

P: n/a
On Feb 12, 3:26 am, Spam Catcher <spamhoney...@rogers.comwrote:
"Deepak" <deepak.m...@gmail.comwrote in news:1171221409.321605.259670
@a34g2000cwb.googlegroups.com:
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?
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.

Feb 12 '07 #3

P: n/a
"Deepak" <de*********@gmail.comwrote in news:1171258144.907950.54910
@l53g2000cwa.googlegroups.com:
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?).
Feb 12 '07 #4

P: n/a
On Feb 12, 10:33 am, Spam Catcher <spamhoney...@rogers.comwrote:
"Deepak" <deepak.m...@gmail.comwrote in news:1171258144.907950.54910
@l53g2000cwa.googlegroups.com:
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 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.

Feb 12 '07 #5

P: n/a
Deepak wrote:
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.

Feb 12 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.