Move IDispatcher logic out of IPlatformServices#2862
Merged
Conversation
27 tasks
PureWeen
reviewed
Oct 7, 2021
PureWeen
reviewed
Oct 7, 2021
mattleibow
commented
Oct 13, 2021
IDispatcher logic out of IPlatformServices
|
I wasn't aware that this was possible in Xamarin.Forms. If it isn't desired in MAUI, maybe we can keep it only in compatibility mode (opt-in). Or, if it is still necessary, I just hope that it doesn't "compromise" the normal way of building UI on their UI thread. I am waiting for multi-window and CollectionView to be available on Windows (in Preview 11 hopefully). Then, I will port my app to MAUI and see if any of these potential issues still occur. Edit: I'm glad to see |
KPixel
reviewed
Nov 11, 2021
KPixel
reviewed
Nov 11, 2021
18 tasks
PureWeen
reviewed
Nov 12, 2021
src/Controls/samples/Controls.Sample.SingleProject/Properties/launchSettings.json
Show resolved
Hide resolved
PureWeen
requested changes
Nov 12, 2021
Co-authored-by: Shane Neuville <shneuvil@microsoft.com>
PureWeen
approved these changes
Nov 13, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of Change
This PR moves the dispatcher and "run on main thread" logic out of the
Forms/Device/IPlatformServicesspace and into Core and Controls.Core has the basic logic for executing on a "platform amin thread" and Controls attaches that logic to all
BindableObjects.Part of #1965
Discussion
Due to backwards compatibility, I have actually implemented this "wrong" in the objective sense. This is because we allow UI objects to be created and used off the UI thread.
For example, If I start up a background thread and on that background thread I create a
Button. Firstly, that is incorrect because logic in the constructor is now running on a background thread. Second, when I use theDispatcherproperty, what thread should I use? Right now I just thrash around and try things until I find one.Now, the thing that sort of holds this together is that there typically is only 1 UI thread. In most cases. Even in Windows with multiple windows because the default way we create windows is on the same thread. So we are lucky. However, this is not fixed. The user or maui may opt to create windows in separate threads - especially if the windows do a lot of work.
We then may enter a world of pain. For example this execution:
myButtonon BmyButton.Dispatcher.Invokefrom B (probably will pick UI 1)myButton.Dispatcher.Invokefrom B :Additions made
IDispatcherandIDispatcherProviderto Core.IMauiContext.MauiContextctors and into the correct scoping methods as they fit better there.Device.Device.*to use the dispatchers.