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!
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.