.Net Windows Forms - Limit navigation form while waiting for asynchronous work

When the button is clicked, the request is executed in the background worker. This is asynchronous, so I can change the Cancel button so that the user can cancel the process if it runs longer than expected. This all works great.

But I don't want the user to be able to move from this location to do other things on the form. They should be able to click the Cancel button or close the form, but nothing else.

+1


a source to share


2 answers


the best way to do this is to create a method like DisableControls () that contains disable commands for all other controls.



After the asynchronous work is complete, call a method such as EnableControls () in the callback to restore the process.

+1


a source


Then I suggest you turn off the other form controls when you start processing your request, and when the background worker finishes, turn them back on.



+6


a source







All Articles