So, I have a site with more than 600 devices. I am trying to ping them 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 he does is ping devices on the network. We are using Microsoft Windows Server 2008 R2. Are there any problems with the ping.NET class? I also seem to experience memory leaks, which I assume are caused by 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(); } } }
source share