Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix UI thread main loop cancellation from another thread on macOS #12579

Merged

Conversation

de1acr0ix
Copy link
Contributor

@de1acr0ix de1acr0ix commented Aug 18, 2023

What does the pull request do?

Ensure that the UI thread main loop is stopped.

What is the current behavior?

Cancelling the UI thread main loop from a different thread does not really stop the loop on macOS.

What is the updated/expected behavior with this PR?

Cancelling the UI thread main loop from a different thread stops the loop on macOS.

How was the solution implemented (if it's not obvious)?

When canceling the UI thread main loop from another thread on macOS, dispatch_async() is used to post the work, [NSApp stop:nil], into the loop. However this will not stop the loop as it doesn't result in the posting of an NSEvent object (see https://developer.apple.com/documentation/appkit/nsapplication/1428473-stop for details). This PR posts the object to ensure the loop is stopped.

This PR also fixes an issue that the Running flag is set too early.

Checklist

Breaking changes

Obsoletions / Deprecations

Fixed issues

@de1acr0ix
Copy link
Contributor Author

@dotnet-policy-service agree

@avaloniaui-team
Copy link
Contributor

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

@de1acr0ix de1acr0ix force-pushed the fix-mainloop-cancellation-hang branch from 9765bc4 to f895661 Compare August 18, 2023 09:02
@avaloniaui-team
Copy link
Contributor

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

@danwalmsley danwalmsley added this pull request to the merge queue Aug 18, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 18, 2023
@maxkatz6 maxkatz6 added this pull request to the merge queue Aug 18, 2023
Merged via the queue into AvaloniaUI:master with commit 0b6294e Aug 18, 2023
@de1acr0ix de1acr0ix deleted the fix-mainloop-cancellation-hang branch August 18, 2023 20:45
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.

5 participants