Back to Devexpress

CRXPF0015 - BeginUpdate call in a loop

coderushforroslyn-404299-static-code-analysis-xaml-analyzers-crxpf-0015-begin-update-call-in-a-loop.md

latest952 B
Original Source

CRXPF0015 - BeginUpdate call in a loop

  • Feb 14, 2023

Severity: Info

The analyzer detects that you call the BeginUpdate method in a loop. In this case, the collection processes updates in each cycle separately.

Examples

Invalid Code

csharp
for ... || foreach ... || while ... || any cycle {
    _gridControl.Columns.BeginUpdate();
    _gridControl.Columns.Add(_newColumn1);
    _gridControl.Columns.Add(_newColumn2);
    _gridControl.Columns.EndUpdate();
}

Valid Code

csharp
_gridControl.Columns.BeginUpdate();
for ... || foreach ... || while ... || any cycle {
    _gridControl.Columns.Add(_newColumn1);
    _gridControl.Columns.Add(_newColumn2);
}
_gridControl.Columns.EndUpdate();

How to Fix

Call the BeginUpdate and EndUpdate methods outside a loop to process all updates in one batch and increase performance.