Skip to content

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

Merged
PureWeen merged 9 commits into
release/8.0.1xx-sr2from
fix_appdispatcher_call
Feb 6, 2024
Merged

If the current thread dispatcher is null return the app level dispatcher#20313
PureWeen merged 9 commits into
release/8.0.1xx-sr2from
fix_appdispatcher_call

Conversation

@PureWeen
Copy link
Copy Markdown
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
Comment thread src/Core/src/Hosting/Dispatching/AppHostBuilderExtensions.cs
Comment thread src/Core/src/Hosting/Dispatching/AppHostBuilderExtensions.cs Outdated
Comment thread src/Controls/src/Core/DispatcherExtensions.cs Outdated
@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
Copy Markdown
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
Copy Markdown
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
Comment thread src/Core/src/Properties/AssemblyInfo.cs
@PureWeen
Copy link
Copy Markdown
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
@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
@samhouts samhouts added fixed-in-9.0.12 and removed fixed-in-net9.0-nightly This may be available in a nightly release! labels Dec 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants