Click here to Skip to main content
16,010,427 members
Home / Discussions / C#
   

C#

 
GeneralRe: Ping Leaking Pin
Dan Neely13-Jul-07 3:55
Dan Neely13-Jul-07 3:55 
GeneralRe: Ping Leaking Pin
kubben13-Jul-07 3:58
kubben13-Jul-07 3:58 
GeneralRe: Ping Leaking Pin
Malcolm Smart13-Jul-07 4:15
Malcolm Smart13-Jul-07 4:15 
GeneralRe: Ping Leaking Pin
kubben13-Jul-07 4:19
kubben13-Jul-07 4:19 
AnswerRe: Ping Leaking Pin
leppie13-Jul-07 3:43
leppie13-Jul-07 3:43 
GeneralRe: Ping Leaking Pin
Malcolm Smart13-Jul-07 3:51
Malcolm Smart13-Jul-07 3:51 
GeneralRe: Ping Leaking Pin
leppie13-Jul-07 4:07
leppie13-Jul-07 4:07 
AnswerRe: Ping Leaking Pin
Malcolm Smart13-Jul-07 5:03
Malcolm Smart13-Jul-07 5:03 
It seems the ASync call of Ping doesn't like havnig hundreds of them kicking about. I changed the code to call the ping synchronously, but placed the call in a worker thread, effectively giving me an asynchronous call. Works a treat..

class pinger
{
   public static int PingsOutstanding = 0;
                    
   public string IP;
   
   public void PingIt()
   {
      try
         {
            //keep count of our pings
            System.Threading.Interlocked.Increment(ref PingsOutstanding);
            Ping ping = new Ping();
            ping.Send(IP, 100);
         }
         catch (Exception e)
         {
            //do really secret stuff
         }
         finally
         {
            System.Threading.Interlocked.Decrement(ref PingsOutstanding);
         }
     }
  }   


//snip loads of stuff to show just the loop to fire off the threads

foreach (string ipAddress in _check.GroupData) //a list of IP Addresses                
{
   //create a pinger class
   pinger p = new pinger();
   p.IP = str;//set the IP address in a nice public member.....demo code - honest!

   //create a new thread and launch the ping
   new System.Threading.Thread(new System.Threading.ThreadStart(p.PingIt)).Start();
}


//keep checking the Pinger static count
while (pinger.PingsOutstanding > 0)
{
   //we're not done yet..
  System.Threading.Thread.Sleep(500);
}
//


This works, perfmon doesn't even blink about the memory being used, and it seems just as quick, if not quicker...happy for destructive criticism on this method!


Thanks all for the help.



"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF

GeneralRe: Ping Leaking Pin
Dave Kreskowiak13-Jul-07 6:30
mveDave Kreskowiak13-Jul-07 6:30 
QuestionJava to C# eBook Pin
Sukhjinder_K13-Jul-07 2:45
Sukhjinder_K13-Jul-07 2:45 
AnswerRe: Java to C# eBook Pin
Christian Graus13-Jul-07 3:24
protectorChristian Graus13-Jul-07 3:24 
AnswerRe: Java to C# eBook Pin
Paul Conrad13-Jul-07 4:03
professionalPaul Conrad13-Jul-07 4:03 
AnswerRe: Java to C# eBook Pin
PhilDanger13-Jul-07 4:23
PhilDanger13-Jul-07 4:23 
GeneralRe: Java to C# eBook Pin
Sukhjinder_K13-Jul-07 4:28
Sukhjinder_K13-Jul-07 4:28 
GeneralRe: Java to C# eBook Pin
leppie13-Jul-07 4:37
leppie13-Jul-07 4:37 
QuestionCSV format to XSL format in C# Programming Pin
liyakhat_shahid13-Jul-07 2:43
liyakhat_shahid13-Jul-07 2:43 
AnswerRe: CSV format to XSL format in C# Programming Pin
Jimmanuel13-Jul-07 7:03
Jimmanuel13-Jul-07 7:03 
GeneralRe: CSV format to XSL format in C# Programming Pin
liyakhat_shahid16-Jul-07 0:02
liyakhat_shahid16-Jul-07 0:02 
GeneralRe: CSV format to XSL format in C# Programming Pin
Jimmanuel16-Jul-07 2:48
Jimmanuel16-Jul-07 2:48 
GeneralRe: CSV format to XSL format in C# Programming Pin
liyakhat_shahid19-Jul-07 2:43
liyakhat_shahid19-Jul-07 2:43 
Questionsqlceme.dll missing Pin
pmartike13-Jul-07 2:13
pmartike13-Jul-07 2:13 
AnswerRe: sqlceme.dll missing Pin
pmartike13-Jul-07 3:20
pmartike13-Jul-07 3:20 
Questionhow to access file at server side and print Pin
absprogrammer13-Jul-07 1:56
absprogrammer13-Jul-07 1:56 
AnswerRe: how to access file at server side and print Pin
Christian Graus13-Jul-07 3:25
protectorChristian Graus13-Jul-07 3:25 
QuestionC# OLE DB sample? Pin
George_George13-Jul-07 1:51
George_George13-Jul-07 1:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.