Q:

C#, Windows Forms: How to prevent firing of EventHandlers while data is retrieved from the backend

I have over 40 controls (TextBox, RadioButton, CheckBoxes, etc.) on Windows Forms. Each control is registered for EventHandlers (TextChanged, CheckChanged, etc.).
I want to prevent these events from firing during initialization of the form.
Unsubscribing all events before initialization and subscribing later is laborious.
Which is the best way to achieve this?

A:

You could enumerate all controls like:
private void DisableAllHandlers()
{
    foreach (var control in this.Controls)
    {
       // Use reflection
    }
}

And use sources from the article How to remove all event handlers from a control to disable handlers for selected control.

