System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping(); System.Net.NetworkInformation.PingReply pingReply = ping.Send("95.213.255.83"); Console.WriteLine(pingReply.RoundtripTime); //время ответа Console.WriteLine(pingReply.Status); //статус Console.WriteLine(pingReply.Address); //IP Console.ReadKey(true); 

I have a button with which I check the ping of the game server (it seems to anyone) If I press more than 190 times, the Internet freezes completely and ping + in general no site responds / opens.

Help who can

  • one
    190 times in a row? What for? Do not open from the computer? Or is it blocking on a router? what tracert shows? - tym32167

1 answer 1

The first thing I would recommend in this case is to use one of the blocks:

This will protect against unforeseen situations, for example, when an exception is thrown out.

The second thing I would advise is the use of the asynchronous version of the Send method. I'm not sure that it is precisely after 190 attempts that everything should become so critical, but I dare to suggest this correction. Best of all, set a timeout (longer than the default timeout for the Ping command), and then call SendAsyncCancel to cancel all pending asynchronous requests before sending SendAsync . You can familiarize yourself with the Ping class and its methods and properties here: the Ping class of the System.Net.NetworkInformation namespace. I also strongly recommend that you read the Comments section of this article. And this will not be superfluous: The Internet Engineering Task Force

Also, I do not recommend creating multiple instances of the type:

 System.Net.NetworkInformation.Ping 

If this code block is looped, then move the ping variable out of this block and use only one instance. Somewhere I stumbled upon an article that had a similar problem and was accompanied by a memory leak.

  • I suffered so much and was looking for an answer .. But even now I have a misunderstanding how this asynchronous connection works. I certainly use it and wonder. Actually everything seems to be working. How many I do not click to update and show the ping server all shows. True with a very small delay, before there was practically no delay. Thank you very much for the advice. I also needed to display information from 1000 servers earlier and show everything in a DataGrid, but I could not do it for this reason (the Internet hung tight after 180 servers or if you connect quickly, then after 150 even. As a result, I put off this function. - Roven Mortano September