Click buffer

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

Hi.

In my app I am have a button which, when clicked, spawns a worker process.
When the user clicks this button, I am setting its Enabled property to false
to disable the button and prevent the user from clicking it again and
spawning a second process. The button is enabled again when the process
finishes.

This works fine, except for the fact that if the user clicks on the button
when it is disabled, the click is buffered. This means that if the user has
clicked on the button when it was disabled, as soon as the worker process
finishes and the button is re-enabled, the click is registered and the
process starts for a second time.

I want to ignore any clicks on the button when it is disabled. Is there
some way I can programmatically turn off or clear the click buffer?

Mike
 
Hi Mike,

I am not sure why you get buffered clicks as I could not reproduce it. All my tests ignored clicks on disabled buttons. You could try to unsubscribe to the click event before running the process and resubscribe after it ends.

private void button1_Click(object sender, System.EventArgs e)
{
button1.Click -= new EventHandler(button1_Click);
button1.Enabled = false;

// do stuff

button1.Enabled = true;
button1.Click += new EventHandler(button1_Click);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top