truenorth12lds
New member
- Joined
- May 23, 2020
- Messages
- 4
- Programming Experience
- Beginner
Is there a way to use Timer1 for all checkbox I create, while still allowing separate pings as desired?
Current operation:
Checkbox1 is checked, Timer1 is started, EHost1 is read and uses Timer1 to do a consistent ping.
Checkbox2 is checked, Timer2 is started, EHost2 is read and uses Timer2 to do a consistent ping.
Checkbox, Timer, and EHost all have to be duplicated for each separate ping I create and perform.
Desired Result:
Checkbox1 is checked, Timer1 is used, EHost1 is read and uses Timer1 to do a consistent ping.
Checkbox2 is checked, Timer1 is used, EHost2 is read and uses Timer1 to do a consistent ping.
Current operation:
Checkbox1 is checked, Timer1 is started, EHost1 is read and uses Timer1 to do a consistent ping.
Checkbox2 is checked, Timer2 is started, EHost2 is read and uses Timer2 to do a consistent ping.
Checkbox, Timer, and EHost all have to be duplicated for each separate ping I create and perform.
Desired Result:
Checkbox1 is checked, Timer1 is used, EHost1 is read and uses Timer1 to do a consistent ping.
Checkbox2 is checked, Timer1 is used, EHost2 is read and uses Timer1 to do a consistent ping.
Timer:
private void timer1_Tick(object sender, EventArgs e)
{
Ping ping = new Ping();
PingReply pingresult = ping.Send((EHost1.Text));
if (pingresult.Status.ToString() == "Success")
{
PingStatus1.Text = "Online!";
}
else
{
PingStatus1.Text = "Offline";
}
CheckBox1 & CheckBox2:
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked == true)
{
timer1.Start();
}
else
{
timer1.Stop();
}
}
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
if (checkBox2.Checked == true)
{
timer2.Start();
}
else
{
timer2.Stop();
}
}