0

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.

  • 2
    I can't explain myself how you get this behaviour. If you disable a control no events are firing and they won't fire after you enable the control again. So nothing is recorded by default. Please post some of your code because this is strange... – Sebi Apr 11 '17 at 10:49
  • I've added an example in my question –  Apr 11 '17 at 11:15

0 Answers0