Support DispatcherQueueSynchronizationContext.Send. #1078
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.
In various places in .NET, the runtime calls SynchronizationContext.Send. For example in the SystemEvents class Send is used: https://github.com/dotnet/runtime/blob/6de7147b9266d7730b0d73ba67632b0c198cb11e/src/libraries/Microsoft.Win32.SystemEvents/src/Microsoft/Win32/SystemEvents.cs#L1326
This means that subscribing to events on the SystemEvents class from the UI thread in a WinUI3 app works, but the event is never fired, because Send throws an exception. There are likely other places where Send is used and where this causes problems for WinUI3 apps.
This PR adds support for Send in a similar to how Xamarin Android does this for the Android main thread: https://github.com/xamarin/xamarin-android/blob/main/src/Mono.Android/Android.App/SyncContext.cs and MAUI for GtkSynchronizationContext: https://github.com/dotnet/maui/blob/18e0f4ebbcca7c904ccdb67e6439cb72382e2a40/src/Compatibility/Core/src/GTK/GtkSynchronizationContext.cs