Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

UWP Dispatcher should use the internal core dispatcher for state #15716

Merged
merged 2 commits into from
Apr 11, 2023

Conversation

mattleibow
Copy link
Contributor

Description of Change

This PR makes sure the UWP dispatcher is using the internal core dispatcher for thread access checks instead of the global device dispatcher which does not support multiple windows.

Issues Resolved

API Changes

None

Platforms Affected

  • UWP

Behavioral/Visual Changes

None

Before/After Screenshots

Not applicable

Testing Procedure

PR Checklist

  • Targets the correct branch
  • Tests are passing (or failures are unrelated)

@jfversluis jfversluis changed the base branch from main to 5.0.0 March 27, 2023 07:20
@jfversluis jfversluis force-pushed the dev/mattleibow/fix-dispatcher branch from b56ff28 to 76bf988 Compare March 27, 2023 07:25
@jfversluis jfversluis added this to To Do in 5.0.0 SR15 Mar 27, 2023
@mattleibow mattleibow marked this pull request as ready for review April 6, 2023 10:40
@mattleibow mattleibow marked this pull request as draft April 6, 2023 13:17
@mattleibow mattleibow marked this pull request as ready for review April 6, 2023 14:22
bool IDispatcher.IsInvokeRequired => Device.IsInvokeRequired;
bool IDispatcher.IsInvokeRequired => !_coreDispatcher.HasThreadAccess;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the main fix to use the correct core dispatcher. The Device.IsInvokeRequired implementation only verifies against the main/first dispatcher.

Comment on lines +30 to +34
else
{
s_current = new Dispatcher();
return s_current;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is to fix the scenario where you try and get the dispatcher before the renderer is created, so we fall back to the window's dispatcher. This is because the dispatcher is cached and if there is no renderer, the FallbackDispatcher is used - and that is always using the first/main thread via the Device.

@jfversluis jfversluis merged commit 3e5cc2b into 5.0.0 Apr 11, 2023
5.0.0 SR15 automation moved this from To Do to Done Apr 11, 2023
@jfversluis jfversluis deleted the dev/mattleibow/fix-dispatcher branch April 11, 2023 19:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

[Bug] Device.IsInvokeRequired is not changing to false after running the method on mainthread
2 participants