So, I have a site with over 600 devices. I'm trying to ping them all one by one using the standard .NET ping class. For some reason, this thread is crashing - it just stops responding after a few days. All it does is ping devices on the network. We're using Microsoft Windows Server 2008 R2. Is there any problems with the .NET ping class? I also seem to be experiencing memory leaks which I'm guessing is due to the pinging. Should I just write a win32 ping dll to do the job for me or am I doing something wrong with .NET?
private void PingDevice(out bool state, string IP)
{
PingReply pingReply;
System.Net.NetworkInformation.Ping pingSender = null;
state = false;
try
{
pingSender = new System.Net.NetworkInformation.Ping();
pingReply = pingSender.Send(IP, 4000);
state = (pingReply.Status == IPStatus.Success); // comms is on/off
}
catch (Exception ex)
{
PingGlobals.driverThread.LogIt("$E Pinging Devices:" + ex.Message + ", " + IP);
}
finally
{
if (pingSender != null)
{
((IDisposable)pingSender).Dispose();
}
}
}