Error System.Net.NetworkInformation.Ping

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(); } } } 
+4
source share
3 answers

When using the asynchronous version of Ping, I found that sometimes Ping never returns. I could imagine that if this happens in Async, then in Sync it just stops. The answer I found for Async is to set a timeout (longer than a Ping timeout), and then call SendAsyncCancel before sending SendAsync.

+2
source

Creating new instances of the System.Net.NetworkInformation.Ping class seems to lead to a memory leak on the 2008 server. If you save one (or one hundred) instances and reuse them, this problem disappears. Just be very careful when accessing it from multiple threads.

+1
source

This is the issue reported for .Net versions below 3.5
There is a Microsoft article describing the problem and its solutions here .

0
source

Source: https://habr.com/ru/post/1443379/


All Articles