Skip to content

Add ListBox BeginUpdate/EndUpdate batching tests and fix SetItemsCore leak - #15421

Merged
Shyam-Gupta merged 1 commit into
mainfrom
dev/shgu/list-box-selection-refresh-tests
Nov 13, 2026
Merged

Shyam-Gupta merged 1 commit into
mainfrom
dev/shgu/list-box-selection-refresh-tests

Conversation

@Shyam-Gupta

@Shyam-Gupta Shyam-Gupta commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

This PR fixes a ListBox redraw suspension leak during failed data-binding refreshes and expands regression coverage for update batching.

Changes

Ensures SetItemsCore calls EndUpdate in a finally block, restoring redraw even when item population throws.
Adds tests for nested batches, handle creation and recreation, disposal, exception recovery, and native selection consistency.

Customer Impact

  • A data-binding refresh that throws while populating the list no longer leaves the ListBox permanently unpainted.

Regression?

  • No

Risk

  • Low. Only the EndUpdate call moves into a finally; the normal path is unchanged.
Microsoft Reviewers: Open in CodeFlow

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the ListBox redraw-recovery fix and its regression coverage.

No open issues 🎉

What changed in this PR

This PR fixes a ListBox redraw suspension leak during failed data-binding refreshes and expands regression coverage for update batching.

Changes:

  • Ensures SetItemsCore calls EndUpdate in a finally block, restoring redraw even when item population throws.
  • Adds tests for nested batches, handle creation and recreation, disposal, exception recovery, and native selection consistency.
File Description
src/​test/​unit/​System.Windows.Forms/​System/​Windows/​Forms/​ListBoxTests.cs Adds redraw tracking and batching regression tests covering native state and failure paths.
src/​System.Windows.Forms/​System/​Windows/​Forms/​Controls/​ListBoxes/​ListBox.cs Guarantees balanced update calls when SetItemsCore throws.

Review effort: Balanced

@Shyam-Gupta
Shyam-Gupta marked this pull request as ready for review November 13, 2026 22:05
@Shyam-Gupta
Shyam-Gupta requested a review from a team as a code owner November 13, 2026 22:05
@Shyam-Gupta

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@codecov

codecov Bot commented Nov 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 39.79260%. Comparing base (160f6d6) to head (61165db).

Additional details and impacted files
@@              Coverage Diff              @@
##                main      #15421   +/-   ##
=============================================
  Coverage   39.79260%   39.79260%           
=============================================
  Files            246         246           
  Lines           9836        9836           
  Branches        1036        1036           
=============================================
  Hits            3914        3914           
  Misses          5741        5741           
  Partials         181         181           
Flag Coverage Δ
Debug 39.79260% <ø> (ø)
production 42.31695% <ø> (ø)
test 19.92786% <ø> (ø)
unit 42.31695% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Shyam-Gupta
Shyam-Gupta merged commit 9c19b69 into main Nov 13, 2026
11 checks passed
@Shyam-Gupta
Shyam-Gupta deleted the dev/shgu/list-box-selection-refresh-tests branch November 13, 2026 22:51
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 14, 2026
@KlausLoeffelmann

Copy link
Copy Markdown
Member

Hey @Shyam-Gupta,

Does this fix a bug we have an issue to?
And if, does this need to back-ported?

@Shyam-Gupta

Copy link
Copy Markdown
Member Author

Found this issue while authoring tests. There is no bug logged for it. It doesn't require back porting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants