Click here to Skip to main content
15,914,488 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hello,

I use this code on click button to test ping to IP address.
I would like to display a progress bar while code is running.
C#
private void button1_Click(object sender, EventArgs e)
        {
            Ping ping = new Ping();
            PingReply pingresult1 = ping.Send("8.8.8.8");
            if (pingresult1.Status.ToString() == "Success")
            {
                lblPing.BackColor= Color.Green;
            }
            else
            {
                lblPing.BackColor = Color.Red;
            }

            PingReply pingresult2 = ping.Send("5.5.5.5");
            if (pingresult2.Status.ToString() == "Success")
            {
                label1.BackColor = Color.Green;
            }
            else
            {
                label1.BackColor = Color.Red;
            }
          
        }
Posted
Updated 21-Mar-14 8:26am
v3
Comments
Dave Kreskowiak 21-Mar-14 15:16pm    
And show the progress of WHAT exactly??

Considering there is no status information coming back from the ping while it's running, then only ProgressBar you can use is a Marquee type, where it just scrolls constantly showing that something is happening, not actual progress being made.
ZurdoDev 21-Mar-14 15:48pm    
When you do it in command prompt you get a few results back but you're still right overall and I think you should post as solution.
Sergey Alexandrovich Kryukov 21-Mar-14 16:54pm    
Is it System.Windows.Forms? Please tag it.
And you are not showing any progress bar. Where? What that progress bar is supposed to show? If you confirm and answer to my questions, I'll be able to answer quickly; the problem looks really simple...
—SA
syed shanu 24-Mar-14 22:20pm    
Chk this http://social.msdn.microsoft.com/Forums/windows/en-US/c357d0d1-5497-4722-9744-a13f6eb94c3e/how-do-i-ping-a-server-or-a-webpage-from-my-windows-form-c?forum=winforms

http://www.c-sharpcorner.com/UploadFile/mahesh/WorkingwithProgressBarinCSharp11302005045625AM/WorkingwithProgressBarinCSharp.aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900