G
Guest
Background:
I am helping someone debug a problem with their form that I have traced to a
strange interaction between a click event handler and Application.DoEvents().
I'm trying to talk him into using mutithreading.
Problem in its essence:
create a simple Form with 2 buttons and a label. button1 starts a
long-running counting process, button 2 stops the counting process. The
first click of the mouse after the button 1 click gets lost. The second and
subsequent clicks work fine.
What's going on?
code snippet (C# .NET 2.0)
bool cancel = false;
int count = 0;
private void button1_Click(object sender, EventArgs e)
{
cancel = false;
while (cancel == false)
{
label1.Text = count.ToString();
Application.DoEvents();
count ++;
}
}
private void button2_Click(object sender, EventArgs e)
{
cancel = true;
}
Thanks
I am helping someone debug a problem with their form that I have traced to a
strange interaction between a click event handler and Application.DoEvents().
I'm trying to talk him into using mutithreading.
Problem in its essence:
create a simple Form with 2 buttons and a label. button1 starts a
long-running counting process, button 2 stops the counting process. The
first click of the mouse after the button 1 click gets lost. The second and
subsequent clicks work fine.
What's going on?
code snippet (C# .NET 2.0)
bool cancel = false;
int count = 0;
private void button1_Click(object sender, EventArgs e)
{
cancel = false;
while (cancel == false)
{
label1.Text = count.ToString();
Application.DoEvents();
count ++;
}
}
private void button2_Click(object sender, EventArgs e)
{
cancel = true;
}
Thanks