Timer is used to monitor whether the network is pinged and timer is pinged.

Source: Internet
Author: User

Timer is used to monitor whether the network is pinged and timer is pinged.

The project needs to connect to a specific server. If the server cannot be connected, the system prompts in real time to start using Timer for real-time detection.

Void timer_Tick (object sender, EventArgs e) {Ping pingSender = new Ping (); PingReply reply = pingSender. Send ("192.168.1.104", 1000); if (reply. Status! = IPStatus. Success) {Message. show ("network exception ")}}

If I run Timer all the time, the memory of the program will keep increasing. Later, the test found that it is not a problem with Timer. Timer has been running without affecting the memory. It is caused by Ping in Timer, it is estimated that there will be a return value after Ping, not cleared

After modification, Ping pingSender = new Ping () to add a PingCompleted event and release it to solve the problem.

Void pingSender_PingCompleted (object sender, PingCompletedEventArgs e) {(sender as IDisposable). Dispose ();}

Follow-up questions:

If a timeout occurs during the ping operation, an error occurs. Make a modification. If the number of ping failures exceeds the specified number of times, an error is returned.

The second problem is whether the computer bandwidth of the IP address will be blocked when thousands of computers are pinging an IP address.

Thank you!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.