Skip to content

Fix WindowCollection removal and non-materialized window objects hanging Application#11766

Open
h3xds1nz wants to merge 2 commits into
dotnet:mainfrom
h3xds1nz:fix-window-destroy-loop
Open

Fix WindowCollection removal and non-materialized window objects hanging Application#11766
h3xds1nz wants to merge 2 commits into
dotnet:mainfrom
h3xds1nz:fix-window-destroy-loop

Conversation

@h3xds1nz

@h3xds1nz h3xds1nz commented Jul 8, 2026

Copy link
Copy Markdown
Member

Fixes #4204
Fixes #11610

Description

Fixes removal of Window objects during explicit app shutdown (forced either via Dispatcher callback or when an app-shutdown condition is detected) and also alters behaviour to shutdown the app when there are non-materialized window objects (windows that don't have / never had a HWND) to stop the process from hanging on a programmer's error.

Customer Impact

I guess customers will be happier this time around that the LLM's poor job is saved by complementary logic? Even though it locks per each closing window now, previously it was an allocation to check the Count (since App.Windows creates a copy), so there's no real difference. Bail is expected on first item in the loop.

Regression

Both has been there since the dark days, so, no.

Testing

Repro in both issues.

Risk

Unlike others, this is a newly crafted fix, so besides the repros it's untested. It changes the behaviour; if you were using OnLastWindowClose (default) and created a Window to hang your app without actually calling EnsureHandle (which you should do), then after merging this you'll be surprised.

Microsoft Reviewers: Open in CodeFlow

@h3xds1nz
h3xds1nz requested a review from a team July 8, 2026 21:48
@h3xds1nz
h3xds1nz requested a review from a team as a code owner July 8, 2026 21:48
@h3xds1nz h3xds1nz self-assigned this Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WindowCollection RemoveAt does not correctly remove window Application hangs on shutdown if a Window was created but never used

1 participant