I want to disable a button while the method does not finish. I used button01.Enabled = false;
, but even clicking while the button is disabled, the method is called again after it finishes.
For example, when I execute the method below and click the button three times during the three seconds it is disabled, "TEST" appears four times in output .
private void buttonSendUsers_Click(object sender, EventArgs e)
{
Console.WriteLine("TEST");
buttonSendUsers.Enabled = false;
Thread.Sleep(3000); //teste
buttonSendUsers.Enabled = true;
return;
}
How can I prevent the button from executing the method while disabled?