1

I'm working on a program that pings a long list of IP addresses. Currently there are about 250 in the database to ping, and it takes a long time to get through all of them. The program also sends email alerts when that status changes (from failed to success or vice versa). At worst, it takes two seconds for each ping (if they fail). So it generally takes about 8 minutes for the whole program to cycle through.

I'd like the email alerts to be closer to real time if possible. Would calling the ping function asynchronously allow them to fire off more quickly without waiting for the response from the one before it? I'm new to non-synchronous programming of any sort, and I'm not sure if this is an appropriate situation to use it in.

If it is, any pointers towards resources for getting started with this would be much appreciated!


  • If you write your own Pinger class using raw sockets, you can use two threads one for sending the ping requests, and the other for receiving. That way, you can ping ,in a few seconds, tausends of machines... - L.B
  • web or windows ? bcuz a lot depends on what you are using ? - Amit Joki
  • It's a Windows Service - eddie_cat
  • where will it run ? In a web server or on a PC ? - Amit Joki
  • Hi, I have application that runs 120 background threads, each thread connect via socket to remote device (TCP). I assume 250 threads will be acceptible too. try it. - ilansch

1 답변


1

The network should support sending 250 pings in below one second. You should probably start all pings at once using async IO, then use Task.WaitAll to collect the results. That way you are done within 2sec.

With 250 work items I would strongly prefer a solution using async IO. You can use threads as well if you like.

Find out what async methods the Ping class provides. Learn about async/await and Task. This is a good use-case for them.


  • Thank you, this is what I was asking about. - eddie_cat

Linked


Related

Latest