Without the do loop, my code runs fine. As soon as I place it within a do or while loop the code fails to update the color status. Any idea? From what I have gathered from the internet, my loops are written correctly.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net.NetworkInformation;
using System.Threading;
namespace SystemsUpDown
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
bool ContinuePing = false;
private void QuitButton_Click(object sender, EventArgs e)
{
this.Close();
}
private void StartButton_Click_1(object sender, EventArgs e)
{
Ping ping = new Ping();
ContinuePing = true;
do
{
try ///ping google
{
PingReply reply = ping.Send("8.8.8.8");
if (reply.Status == IPStatus.Success)
{
GoogleStatusLabel.BackColor = Color.Green;
}
}
catch
{
GoogleStatusLabel.BackColor = Color.Red;
}
try ///ping Yahoo!
{
PingReply reply = ping.Send("www.yahoo.com");
if (reply.Status == IPStatus.Success)
{
YahooStatusLabel.BackColor = Color.Green;
}
}
catch
{
YahooStatusLabel.BackColor = Color.Red;
}
try ///ping Reddit.com
{
PingReply reply = ping.Send("www.reddit.com");
if (reply.Status == IPStatus.Success)
{
RedditStatusLabel.BackColor = Color.Green;
}
}
catch
{
RedditStatusLabel.BackColor = Color.Red;
}
try ///ping Chive
{
PingReply reply = ping.Send("www.chive.com");
if (reply.Status == IPStatus.Success)
{
ChiveStatusLabel.BackColor = Color.Green;
}
}
catch
{
ChiveStatusLabel.BackColor = Color.Red;
}
try ///ping CNN
{
PingReply reply = ping.Send("www.cnn.com");
if (reply.Status == IPStatus.Success)
{
CNNStatusLabel.BackColor = Color.Green;
}
}
catch
{
CNNStatusLabel.BackColor = Color.Red;
}
} while (ContinuePing);
}
private void StopButton_Click(object sender, EventArgs e)
{
GoogleStatusLabel.BackColor = Color.Yellow;
ChiveStatusLabel.BackColor = Color.Yellow;
CNNStatusLabel.BackColor = Color.Yellow;
RedditStatusLabel.BackColor = Color.Yellow;
YahooStatusLabel.BackColor = Color.Yellow;
ContinuePing = false;
}
}
}