Handle transient GDI+ ExternalException in SplitContainer.RepaintSplitterRect during display-session transition#14565
Open
LeafShi1 wants to merge 2 commits into
Conversation
…tterRect during display-session transition
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request prevents intermittent crashes in WinForms SplitContainer during display-session transitions (e.g., Windows lock/unlock) by handling transient GDI+ failures that can occur when repainting the splitter during layout.
Changes:
- Wrap
SplitContainer.RepaintSplitterRect()immediate GDI+ drawing in atry/catch (ExternalException). - Suppress transient GDI+ repaint failures so layout/painting can recover on subsequent paint cycles.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ricardobossan
approved these changes
May 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #14562
Root Cause
SplitContainer.RepaintSplitterRect()performs immediate GDI+ drawing during layout (CreateGraphicsInternal+FillRectangle).During display-session transitions (for example, Windows lock/unlock), the graphics context can become transiently invalid and GDI+ may throw
ExternalException(A generic error occurred in GDI+).This exception was previously unhandled in this path and could bubble up as an unhandled exception.
Proposed changes
SplitContainer.RepaintSplitterRect():try/catch (ExternalException).Customer Impact
SplitContainerRegression?
Risk
Screenshots
Sample project: WinFormsApp5.zip
Before
When a window containing
SplitContaineris opened and the machine is locked before layout completes, unlocking can trigger an unhandled error dialog (“A generic error occurred in GDI+”).After
Under the same lock/unlock timing, users no longer see the GDI+ error dialog and the app does not crash from this path.
The window opens and continues rendering normally after unlock, with no new UI changes in normal scenarios.
Test methodology
Test environment(s)
Microsoft Reviewers: Open in CodeFlow