S
Sam Sungshik Kong
Hello!
I have a form with 2 buttons.
If you click button1, it runs a loop which changes the form's text from 0 to
99.
I added Sleep(500) to make it slow.
If you click button2 while the above routine runs, the loop should stop
there.
Here's my code.
private void button1_Click(object sender, EventArgs e)
{
bContinue = true;
for (int i = 0; i < 100; i++)
{
Text = i.ToString();
Application.DoEvents();
if (!bContinue) break;
Thread.Sleep(500);
}
}
bool bContinue;
private void button2_Click(object sender, EventArgs e)
{
Application.DoEvents(); //this doesn't help whether it's here
not not.
bContinue = false;
}
The problem is that if I click button2, it's ignored and button1 looks to be
clicked instead. If I click button2 one more time, it works as I wish.
What's the problem here?
TIA.
Sam
I have a form with 2 buttons.
If you click button1, it runs a loop which changes the form's text from 0 to
99.
I added Sleep(500) to make it slow.
If you click button2 while the above routine runs, the loop should stop
there.
Here's my code.
private void button1_Click(object sender, EventArgs e)
{
bContinue = true;
for (int i = 0; i < 100; i++)
{
Text = i.ToString();
Application.DoEvents();
if (!bContinue) break;
Thread.Sleep(500);
}
}
bool bContinue;
private void button2_Click(object sender, EventArgs e)
{
Application.DoEvents(); //this doesn't help whether it's here
not not.
bContinue = false;
}
The problem is that if I click button2, it's ignored and button1 looks to be
clicked instead. If I click button2 one more time, it works as I wish.
What's the problem here?
TIA.
Sam