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

If the current thread dispatcher is null return the app level dispatcher #20313

Merged
merged 9 commits into from
Feb 6, 2024

Conversation

PureWeen
Copy link
Member

@PureWeen PureWeen commented Feb 2, 2024

Description of Change

Account for scenarios where the first call to the application level IDispatcher is from a background thread.

  • We modify the logic of FindDispatcher to fall back to our ApplicationDispatcher container. This means if the user calls Application.Current.Dispatcher from a background thread they won't fail.
  • We also added a coalesce inside the factory call for "IDispatcher".
    • The main purpose of this is to account for users calling IPlatformApplication.Current.Services.Get<IDispatcher>() from a background thread. Because we're no longer initializing that path via initializers we need to account for the case where a user is trying to resolve a scoped service from the static container.
    • If users try to request the window level dispatcher from a background thread, they will still get the correct dispatcher because now we're initializing that dispatcher whenever a scoped service is created. In the current stable version of NET8 (8.0.6) if a users first request for the dispatcher is from a background thread it'll return null, and they'll be stuck in a bad state.

@PureWeen PureWeen requested a review from mattleibow February 2, 2024 16:03
@PureWeen PureWeen requested a review from mattleibow February 3, 2024 22:11
@PureWeen PureWeen marked this pull request as ready for review February 5, 2024 23:39
@PureWeen PureWeen requested a review from a team as a code owner February 5, 2024 23:39
@PureWeen PureWeen requested review from StephaneDelcroix and removed request for a team February 5, 2024 23:39
@PureWeen PureWeen added this to the .NET 8 SR2 milestone Feb 5, 2024
Copy link
Contributor

@jsuarezruiz jsuarezruiz left a comment

Choose a reason for hiding this comment

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

D:\a\_work\1\s\src\Compatibility\ControlGallery\src\Issues.Shared\TestPages\TestPages.cs(962,17): error CS0122: 'ApplicationDispatcher' is inaccessible due to its protection level [D:\a\_work\1\s\src\Compatibility\ControlGallery\test\WinUI.UITests\WinUI.UITests.csproj]

@PureWeen
Copy link
Member Author

PureWeen commented Feb 6, 2024

/rebase

@github-actions github-actions bot force-pushed the fix_appdispatcher_call branch from 15da882 to 4a3bcab Compare February 6, 2024 15:12
@PureWeen
Copy link
Member Author

PureWeen commented Feb 6, 2024

iOS failures are unrelated

@PureWeen PureWeen merged commit 2e9bb17 into release/8.0.1xx-sr2 Feb 6, 2024
8 of 12 checks passed
@PureWeen PureWeen deleted the fix_appdispatcher_call branch February 6, 2024 18:20
@github-actions github-actions bot locked and limited conversation to collaborators Mar 8, 2024
@samhouts samhouts added fixed-in-8.0.7 fixed-in-net9.0-nightly This may be available in a nightly release! labels Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
fixed-in-8.0.7 fixed-in-net9.0-nightly This may be available in a nightly release!
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants