Back to Devexpress

DXWIN0004: EndUpdate Missing

windowsforms-403883-build-an-application-security-considerations-code-diagnostics-win-004-message.md

latest1.1 KB
Original Source

DXWIN0004: EndUpdate Missing

  • May 06, 2022

Severity: Warning

The BeginUpdate method locks a control and prevents any visual updates to this control, which allows you to apply a large number of changes without triggering excessive redraw commands. After all edits are applied, call the EndUpdate method to unlock the control.

Example 1

Invalid Code

csharp
public void UpdateView(GridView view) {
    view.BeginUpdate();
    // Update operations
}

Valid Code

csharp
public void UpdateView(GridView view) {
    view.BeginUpdate();
    // Update operations
    view.EndUpdate();
}

Example 2

Invalid Code

csharp
public void UpdateView(GridView view) {
    try {
        view.BeginUpdate();
        // Update operations
        view.EndUpdate(); // Not called if an exception occurs in the code above
        }
    catch { }
    finally { }
}

Valid Code

csharp
public void UpdateView(GridView view) {
    try {
        view.BeginUpdate();
        // Update operations
    }
    catch { }
    finally {
        view.EndUpdate(); // The EndUpdate method is always reachable
    }
}