I want to stop a timer but in the middle of the tick, before the tick finishes. But when I use a button to stop the timer, it only stops it after the tick finishes all his functions.
I'm using 4 radiobuttons and a timer that keeps changing the selected radiobutton. When I press the Stop button, my timer stops and I need to know what radiobutton is selected, but the timer just stops after the tick finishes, so the selected radiobutton changes.
The code is:
namespace teste_bola
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Int32 x = 1000;
private void ini_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
private void par_Click(object sender, EventArgs e)
{
timer1.Enabled = false;
}
private void t_Click(object sender, EventArgs e)
{
Int32 Intervalo = Convert.ToInt32(tb.Text);
x = Intervalo;
}
private void timer1_Tick(object sender, EventArgs e)
{
r3.Select();
System.Threading.Thread.Sleep(x);
r2.Select();
System.Threading.Thread.Sleep(x);
r1.Select();
System.Threading.Thread.Sleep(x);
r2.Select();
System.Threading.Thread.Sleep(x);
r3.Select();
System.Threading.Thread.Sleep(x);
r4.Select();
System.Threading.Thread.Sleep(x);
}
}
}