[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2062
  • Last Modified:

Continuous SendAsync Ping in VB.Net

I have 4 servers that I need to ping.  I can easily ping them all once with .SendAsync pinging method.  Works great!  I get my response back nicely from the PingCompleted Event.

1. I have setup 4 Ping Objects, one for each server
2. Each has it's own PingComplete handler to update screen reporting
3. I execute the Server1.SendAsync(address, address) for each (Server1-Server4 respectively)

How can I have their pings repeat once a second till I send a Server1.SendAsyncCancel?  This will be a separate button on the screen labelled 'STOP'  I will send a .SendAsyncCancel for each Ping object.  Server1 - Server4 respectively again.

I tried placing an additional Server1.SendAsync(address, address) statement at the end of the PingComplete event to execute another ping and the pings are cruising at warp speed.  I definitely don't want to add a system.thread sleep statment anywhere in there.  That will pause the whole app.  The .SendAsyncCancel sometimes get's ignored it's going so fast.

Does anyone have a good VB.Net example of pinging multiple address multiple times?  And reporting on the reply for each.  (return time, ip address, etc...)
  • 2
1 Solution
If you are truly sending async then they should be running in their own thread and a Thread.Sleep will not halt your application.  If in fact this is not the case, then try creatiing timers that fire every second and call the ping method.  You can have a start and stop button that will just start and stop the timers that are calling the ping methods.
gbrdelormfAuthor Commented:
I created 4 timers, one for each server.  Set the interval to 1000.  Placed the Server1.SendAsync(...) statement in there.  Test Run.  If the ping has not returned with 1000ms, it errors that I cannot launch another SendAsync while one is active.  Any ideas?
You can use a boolean flag to check if the ping method has completed.  Set it true at the end of the ping method and in your timer check to see if it has completed and if so, then run it again.

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now