So when I disable my form or a button for a long running task and click on it whilst the control is disabled, nothing happens immediately but when the task is complete, the recorded clicks execute.
How can I prevent this behaviour. If a control is disabled, I do not want the code to execute when it becomes enabled.
Specifically, I'm looking to disable the entire Form and prevent clicks on any controls inside the form whilst they are disabled.
Example Code
Private Sub Button_Click(sender As Object, e As EventArgs) Handles Button.Click
Button.Enabled = False
Threading.Thread.Sleep(5000)
Button.Enabled = True
End Sub
If you put a break point inside this code, click on the disabled button whilst the task is running, you'll see that the code runs again after the click event completes.