Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8852727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:28:25+00:00 2026-06-14T13:28:25+00:00

I have a windows form application that basically pings an ip and then returns

  • 0

I have a windows form application that basically pings an ip and then returns an image with a tooltip that displays the rtt to that ip.

What i want to do is have the the form ping that ip every 20 seconds, so that the form and images change. If i could get that to work then I would like to some how store maybe 4 rtt’s and then show an average of the 4 in the tooltip.

So far the form is only pinging once, I’ve played around with a timer but I don’t really know what I am doing. Here is my code so far.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.NetworkInformation;
using System.ServiceProcess;
using System.Threading;
using System.ComponentModel;



namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public void Form1_Load(object sender, EventArgs e)
        {
            Ping pingClass = new Ping();
            PingReply pingReply = pingClass.Send("10.209.123.123");
            label4.Text = (pingReply.RoundtripTime.ToString());
            //+ "ms");
            label5.Text = (pingReply.Status.ToString());



            if (Convert.ToInt32(label4.Text) > 0 && Convert.ToInt32(label4.Text) < 100)
                this.pictureBox1.Load("greenLAT.png");

            if (Convert.ToInt32(label4.Text) > 100 && Convert.ToInt32(label4.Text) < 200)
                this.pictureBox1.Load("yellowLAT.png");

            if (Convert.ToInt32(label4.Text) > 200 && Convert.ToInt32(label4.Text) < 1000)
                this.pictureBox1.Load("redLAT.png");

            ToolTip tt = new ToolTip();
            tt.SetToolTip(this.pictureBox1, "Your current network delay is " + label4.Text + "ms");

            timer1.Interval = 1000;
            timer1.Tick += new EventHandler(timer1_Tick);
            timer1.Start();

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            //MessageBox.Show("Timeout!");
            Refresh();



        }


    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:28:26+00:00Added an answer on June 14, 2026 at 1:28 pm

    Try this:

    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Globalization;
    using System.Net;
    using System.Windows.Forms;
    using System.Net.NetworkInformation;
    
    
    
    namespace DXWindowsApplication4
    {
        public partial class Form2 : Form
        {
            private readonly Timer _timer;
            private readonly Ping _pingClass;
            private readonly IPAddress _ipAddress;
            private readonly int _timeout;
    
            private Image _greenImage; 
            private Image _yellowImage; 
            private Image _redImage; 
    
            private int _pingCount;
            private long _avgRtt;
    
            public Form2()
            {
                InitializeComponent();
                IPAddress.TryParse("98.138.253.109", out _ipAddress); // yahoo.com Ip address
                _timer = new Timer();
                _timeout = 3000;
                _pingClass = new Ping();
                _pingClass.PingCompleted += PingClassPingCompleted;
            }
    
            void PingClassPingCompleted(object sender, PingCompletedEventArgs e)
            {
                RefreshPing(e.Reply);
            }
    
            public void FormLoad(object sender, EventArgs e)
            {
                _timer.Tick += TimerTick;
                _timer.Interval = 4000;
                _timer.Start();
            }
    
            private void TimerTick(object sender, EventArgs e)
            {
                _pingClass.SendAsync(_ipAddress, _timeout);
            }
    
            private void RefreshPing(PingReply pingReply)
            {
                label4.Text = (pingReply.RoundtripTime.ToString(CultureInfo.InstalledUICulture));
                label5.Text = (pingReply.Status.ToString());
    
                _avgRtt = (_avgRtt * _pingCount++ + pingReply.RoundtripTime)/_pingCount;
    
                if (Convert.ToInt32(label4.Text) > 0 && Convert.ToInt32(label4.Text) < 100)
                {
                    SetImage(pictureBox1, Images.Green);
                }
    
                if (Convert.ToInt32(label4.Text) > 100 && Convert.ToInt32(label4.Text) < 200)
                {
                    SetImage(pictureBox1, Images.Yellow);
                }
    
                if (Convert.ToInt32(label4.Text) > 200 && Convert.ToInt32(label4.Text) < 1000)
                {
                    SetImage(pictureBox1, Images.Red);
                }
    
                ToolTip tt = new ToolTip();
                tt.SetToolTip(pictureBox1, "Your average network delay is " + _avgRtt + "ms");
                Refresh();
            }
    
            private void SetImage(PictureBox pBox, Images images)
            {
                switch (images)
                {
                    case Images.Green:
                        if (_greenImage == null)
                        {
                            _greenImage = new Bitmap("greenImage.png");
                        }
    
                        pictureBox1.Image = _greenImage;
                        break;
                    case Images.Yellow:
                        if (_greenImage == null)
                        {
                            _yellowImage = new Bitmap("yellowImage.png");
                        }
    
                        pictureBox1.Image = _yellowImage;
                        break;
                    case Images.Red:
                        if (_redImage == null)
                        {
                            _redImage = new Bitmap("redImage.png");
                        }
    
                        pictureBox1.Image = _greenImage;
                        break;
                    default:
                        throw new InvalidEnumArgumentException("invalid enum name");
                }
            }
        }
    
        internal enum Images
        {
            Green,
            Yellow,
            Red
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Windows form application that's consuming web services over https and is
I have a C# Windows Form application that contains a menu with this event:
I have a combo box in a C# Windows form application that is being
I have a Windows application that has 2 Forms . From one form I
I am using windows application and I have four combo boxes(comboeventname,combosendtype,comboType,comboschedule) in that form....
I have a windows form application that connects to a USB port. In the
Windows form application. C# 4.0. Basically I have two datagridviews dgv1 and dgv2. One
I have written a Silverlight application that is basically an account registration form. I
I have a Windows Form application that, when the form is Activated, Deactivated, or
I have a Windows Form application that involves two Forms. The child form is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.