Skip to content

Unify shutdown handling and subscribe UI dispatcher event - #22155

Open
RyouDYFZ wants to merge 1 commit into
AvaloniaUI:mainfrom
RyouDYFZ:ShutdownHandling
Open

Unify shutdown handling and subscribe UI dispatcher event#22155
RyouDYFZ wants to merge 1 commit into
AvaloniaUI:mainfrom
RyouDYFZ:ShutdownHandling

Conversation

@RyouDYFZ

@RyouDYFZ RyouDYFZ commented Sep 6, 2026

Copy link
Copy Markdown

What does the pull request do?

Releases Avalonia Native resources when the UI dispatcher finishes shutting down, addressing the late release of managed callbacks reported in #22062

What is the current behavior?

Native factory cleanup relies exclusively on AppDomain.ProcessExit. Managed callbacks can remain referenced by native static storage until runtime teardown, causing the reported macOS shutdown crash on .NET 11.

What is the updated/expected behavior with this PR?

The native factory is disposed before the desktop application’s main loop returns. ProcessExit remains a fallback when dispatcher shutdown does not occur.

Checklist

Fixed issues

Fixes #22062

Replace the previous ProcessExit-only handler with a unified OnShutdown handler in AvaloniaNativePlatform. The code now subscribes to Dispatcher.UIThread.ShutdownFinished as well as AppDomain.CurrentDomain.ProcessExit, and the handler unsubscribes from both before disposing the native factory.
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.2.999-cibuild0069465-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@cla-avalonia

cla-avalonia commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator
  • All contributors have signed the CLA.

@RyouDYFZ

RyouDYFZ commented Sep 6, 2026

Copy link
Copy Markdown
Author

@cla-avalonia agree

@maxkatz6 maxkatz6 added bug os-macos backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch labels Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch bug os-macos

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[macOS] .NET 11 shutdown crash when AvaloniaNative releases managed dispatcher after CoreCLR thread teardown

4 participants