Skip to content

Expose DispatcherExtensions so it could be used outside of Maui as well #30488

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

Open
wants to merge 4 commits into
base: net10.0
Choose a base branch
from

Conversation

Vignesh-SF3580
Copy link
Contributor

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Description of Change

Exposing the DispatcherExtensions so it could be used outside of Maui as well.

Issues Fixed

Fixes #29258

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Jul 8, 2025
Copy link
Contributor

Hey there @@Vignesh-SF3580! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@jsuarezruiz
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@Vignesh-SF3580 Vignesh-SF3580 marked this pull request as ready for review July 9, 2025 05:03
@Copilot Copilot AI review requested due to automatic review settings July 9, 2025 05:03
@Vignesh-SF3580 Vignesh-SF3580 requested a review from a team as a code owner July 9, 2025 05:03
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR exposes new DispatcherExtensions methods so they can be used outside of .NET MAUI and updates the Public API accordingly.

  • Adds DispatchIfRequired and multiple DispatchIfRequiredAsync overloads to DispatcherExtensions
  • Updates unit tests to cover all new extension overloads
  • Removes duplicate dispatcher helpers in Controls and adds necessary using directives

Reviewed Changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Core/src/Dispatching/DispatcherExtensions.cs Added new DispatchIfRequired and various DispatchIfRequiredAsync extension methods
src/Core/tests/UnitTests/Dispatching/DispatcherTests.cs Added 14 new facts to verify each overload of the new extension methods
src/Core/src/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt Registered the new extension methods in the Public API
src/Core/src/PublicAPI/netstandard/PublicAPI.Unshipped.txt Registered the new extension methods in the Public API
src/Core/src/PublicAPI/net/PublicAPI.Unshipped.txt Registered the new extension methods in the Public API
src/Core/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt Registered the new extension methods in the Public API
src/Core/src/PublicAPI/net-tizen/PublicAPI.Unshipped.txt Registered the new extension methods in the Public API
src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt Registered the new extension methods in the Public API
src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt Registered the new extension methods in the Public API
src/Core/src/PublicAPI/net-android/PublicAPI.Unshipped.txt Registered the new extension methods in the Public API
src/Controls/src/Core/Handlers/Items/Android/ItemsSources/ObservableItemsSource.cs Added using Microsoft.Maui.Dispatching; to use shared dispatcher extensions
src/Controls/src/Core/Handlers/Items/Android/ItemsSources/ObservableGroupedSource.cs Added using Microsoft.Maui.Dispatching; to use shared dispatcher extensions
src/Controls/src/Core/DispatcherExtensions.cs Removed local DispatchIfRequired* implementations in favor of the shared ones in Core
src/Controls/src/Core/BindingExpression.cs Added using Microsoft.Maui.Dispatching;
src/Controls/src/Core/AppThemeBinding.cs Added using Microsoft.Maui.Dispatching;
Comments suppressed due to low confidence (4)

src/Core/src/Dispatching/DispatcherExtensions.cs:97

  • New public extension methods require corresponding updates to the official documentation (under /docs) to describe DispatchIfRequired and its overloads.
		public static void DispatchIfRequired(this IDispatcher dispatcher, Action action)

src/Core/src/Dispatching/DispatcherExtensions.cs:112

  • Fill in the <param> and <returns> XML comments for the DispatchIfRequiredAsync overloads to clearly document parameters and return values.
		/// <param name="dispatcher"></param>

src/Controls/src/Core/BindingExpression.cs:13

  • [nitpick] This using directive appears unused in this file; consider removing it to keep imports clean.
using Microsoft.Maui.Dispatching;

src/Controls/src/Core/AppThemeBinding.cs:6

  • [nitpick] This using directive appears unused in this file; consider removing it to keep imports clean.
using Microsoft.Maui.Dispatching;

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.

There are some build errors:

C:\a\_work\1\s\src\Controls\src\Core\Platform\Windows\CollectionView\GroupedItemTemplateCollection.cs(83,26): error CS1061: 'IDispatcher' does not contain a definition for 'DispatchIfRequired' and no accessible extension method 'DispatchIfRequired' accepting a first argument of type 'IDispatcher' could be found (are you missing a using directive or an assembly reference?) [C:\a\_work\1\s\src\Controls\src\Core\Controls.Core.csproj::TargetFramework=net10.0-windows10.0.19041.0]
C:\a\_work\1\s\src\Controls\src\Core\Platform\Windows\CollectionView\ObservableItemTemplateCollection.cs(146,26): error CS1061: 'IDispatcher' does not contain a definition for 'DispatchIfRequired' and no accessible extension method 'DispatchIfRequired' accepting a first argument of type 'IDispatcher' could be found (are you missing a using directive or an assembly reference?) [C:\a\_work\1\s\src\Controls\src\Core\Controls.Core.csproj::TargetFramework=net10.0-windows10.0.19041.0]
C:\Users\cloudtest\.nuget\packages\microsoft.windowsappsdk\1.7.250606001\buildTransitive\Microsoft.UI.Xaml.Markup.Compiler.interop.targets(845,9): error MSB3073: The command ""C:\Users\cloudtest\.nuget\packages\microsoft.windowsappsdk\1.7.250606001\buildTransitive\..\tools\net6.0\..\net472\XamlCompiler.exe" "C:\a\_work\1\s\artifacts\obj\Controls.Core\Release\net10.0-windows10.0.19041.0\\input.json" "C:\a\_work\1\s\artifacts\obj\Controls.Core\Release\net10.0-windows10.0.19041.0\\output.json"" exited with code 1. [C:\a\_work\1\s\src\Controls\src\Core\Controls.Core.csproj::TargetFramework=net10.0-windows10.0.19041.0]
C:\a\_work\1\s\src\Compatibility\Core\src\iOS\VisualElementTracker.cs(347,21): error CS1061: 'IDispatcher' does not contain a definition for 'DispatchIfRequired' and no accessible extension method 'DispatchIfRequired' accepting a first argument of type 'IDispatcher' could be found (are you missing a using directive or an assembly reference?) [C:\a\_work\1\s\src\Compatibility\Core\src\Compatibility.csproj::TargetFramework=net10.0-ios18.5]
C:\a\_work\1\s\src\Compatibility\Core\src\iOS\VisualElementTracker.cs(347,21): error CS1061: 'IDispatcher' does not contain a definition for 'DispatchIfRequired' and no accessible extension method 'DispatchIfRequired' accepting a first argument of type 'IDispatcher' could be found (are you missing a using directive or an assembly reference?) [C:\a\_work\1\s\src\Compatibility\Core\src\Compatibility.csproj::TargetFramework=net10.0-maccatalyst18.5]
C:\a\_work\1\s\src\Controls\src\Core\Platform\Windows\CollectionView\ObservableItemTemplateCollection.cs(146,26): error CS1061: 'IDispatcher' does not contain a definition for 'DispatchIfRequired' and no accessible extension method 'DispatchIfRequired' accepting a first argument of type 'IDispatcher' could be found (are you missing a using directive or an assembly reference?) [C:\a\_work\1\s\src\Controls\src\Core\Controls.Core.csproj::TargetFramework=net10.0-windows10.0.20348.0]
C:\a\_work\1\s\src\Controls\src\Core\Platform\Windows\CollectionView\GroupedItemTemplateCollection.cs(83,26): error CS1061: 'IDispatcher' does not contain a definition for 'DispatchIfRequired' and no accessible extension method 'DispatchIfRequired' accepting a first argument of type 'IDispatcher' could be found (are you missing a using directive or an assembly reference?) [C:\a\_work\1\s\src\Controls\src\Core\Controls.Core.csproj::TargetFramework=net10.0-windows10.0.20348.0]
C:\Users\cloudtest\.nuget\packages\microsoft.windowsappsdk\1.7.250606001\buildTransitive\Microsoft.UI.Xaml.Markup.Compiler.interop.targets(845,9): error MSB3073: The command ""C:\Users\cloudtest\.nuget\packages\microsoft.windowsappsdk\1.7.250606001\buildTransitive\..\tools\net6.0\..\net472\XamlCompiler.exe" "C:\a\_work\1\s\artifacts\obj\Controls.Core\Release\net10.0-windows10.0.20348.0\\input.json" "C:\a\_work\1\s\artifacts\obj\Controls.Core\Release\net10.0-windows10.0.20348.0\\output.json"" exited with code 1. [C:\a\_work\1\s\src\Controls\src\Core\Controls.Core.csproj::TargetFramework=net10.0-windows10.0.20348.0]
C:\a\_work\1\s\src\Compatibility\Core\src\Android\CollectionView\ObservableGroupedSource.cs(235,35): error CS1061: 'IDispatcher' does not contain a definition for 'DispatchIfRequired' and no accessible extension method 'DispatchIfRequired' accepting a first argument of type 'IDispatcher' could be found (are you missing a using directive or an assembly reference?) [C:\a\_work\1\s\src\Compatibility\Core\src\Compatibility.csproj::TargetFramework=net10.0-android36.0]
C:\a\_work\1\s\src\Compatibility\Core\src\Android\CollectionView\ObservableItemsSource.cs(94,26): error CS1061: 'IDispatcher' does not contain a definition for 'DispatchIfRequired' and no accessible extension method 'DispatchIfRequired' accepting a first argument of type 'IDispatcher' could be found (are you missing a using directive or an assembly reference?) [C:\a\_work\1\s\src\Compatibility\Core\src\Compatibility.csproj::TargetFramework=net10.0-android36.0]
    10 Error(s)

Could you review it?

@github-project-automation github-project-automation bot moved this from Todo to Changes Requested in MAUI SDK Ongoing Jul 9, 2025
@Vignesh-SF3580
Copy link
Contributor Author

There are some build errors:

C:\a\_work\1\s\src\Controls\src\Core\Platform\Windows\CollectionView\GroupedItemTemplateCollection.cs(83,26): error CS1061: 'IDispatcher' does not contain a definition for 'DispatchIfRequired' and no accessible extension method 'DispatchIfRequired' accepting a first argument of type 'IDispatcher' could be found (are you missing a using directive or an assembly reference?) [C:\a\_work\1\s\src\Controls\src\Core\Controls.Core.csproj::TargetFramework=net10.0-windows10.0.19041.0]
C:\a\_work\1\s\src\Controls\src\Core\Platform\Windows\CollectionView\ObservableItemTemplateCollection.cs(146,26): error CS1061: 'IDispatcher' does not contain a definition for 'DispatchIfRequired' and no accessible extension method 'DispatchIfRequired' accepting a first argument of type 'IDispatcher' could be found (are you missing a using directive or an assembly reference?) [C:\a\_work\1\s\src\Controls\src\Core\Controls.Core.csproj::TargetFramework=net10.0-windows10.0.19041.0]
C:\Users\cloudtest\.nuget\packages\microsoft.windowsappsdk\1.7.250606001\buildTransitive\Microsoft.UI.Xaml.Markup.Compiler.interop.targets(845,9): error MSB3073: The command ""C:\Users\cloudtest\.nuget\packages\microsoft.windowsappsdk\1.7.250606001\buildTransitive\..\tools\net6.0\..\net472\XamlCompiler.exe" "C:\a\_work\1\s\artifacts\obj\Controls.Core\Release\net10.0-windows10.0.19041.0\\input.json" "C:\a\_work\1\s\artifacts\obj\Controls.Core\Release\net10.0-windows10.0.19041.0\\output.json"" exited with code 1. [C:\a\_work\1\s\src\Controls\src\Core\Controls.Core.csproj::TargetFramework=net10.0-windows10.0.19041.0]
C:\a\_work\1\s\src\Compatibility\Core\src\iOS\VisualElementTracker.cs(347,21): error CS1061: 'IDispatcher' does not contain a definition for 'DispatchIfRequired' and no accessible extension method 'DispatchIfRequired' accepting a first argument of type 'IDispatcher' could be found (are you missing a using directive or an assembly reference?) [C:\a\_work\1\s\src\Compatibility\Core\src\Compatibility.csproj::TargetFramework=net10.0-ios18.5]
C:\a\_work\1\s\src\Compatibility\Core\src\iOS\VisualElementTracker.cs(347,21): error CS1061: 'IDispatcher' does not contain a definition for 'DispatchIfRequired' and no accessible extension method 'DispatchIfRequired' accepting a first argument of type 'IDispatcher' could be found (are you missing a using directive or an assembly reference?) [C:\a\_work\1\s\src\Compatibility\Core\src\Compatibility.csproj::TargetFramework=net10.0-maccatalyst18.5]
C:\a\_work\1\s\src\Controls\src\Core\Platform\Windows\CollectionView\ObservableItemTemplateCollection.cs(146,26): error CS1061: 'IDispatcher' does not contain a definition for 'DispatchIfRequired' and no accessible extension method 'DispatchIfRequired' accepting a first argument of type 'IDispatcher' could be found (are you missing a using directive or an assembly reference?) [C:\a\_work\1\s\src\Controls\src\Core\Controls.Core.csproj::TargetFramework=net10.0-windows10.0.20348.0]
C:\a\_work\1\s\src\Controls\src\Core\Platform\Windows\CollectionView\GroupedItemTemplateCollection.cs(83,26): error CS1061: 'IDispatcher' does not contain a definition for 'DispatchIfRequired' and no accessible extension method 'DispatchIfRequired' accepting a first argument of type 'IDispatcher' could be found (are you missing a using directive or an assembly reference?) [C:\a\_work\1\s\src\Controls\src\Core\Controls.Core.csproj::TargetFramework=net10.0-windows10.0.20348.0]
C:\Users\cloudtest\.nuget\packages\microsoft.windowsappsdk\1.7.250606001\buildTransitive\Microsoft.UI.Xaml.Markup.Compiler.interop.targets(845,9): error MSB3073: The command ""C:\Users\cloudtest\.nuget\packages\microsoft.windowsappsdk\1.7.250606001\buildTransitive\..\tools\net6.0\..\net472\XamlCompiler.exe" "C:\a\_work\1\s\artifacts\obj\Controls.Core\Release\net10.0-windows10.0.20348.0\\input.json" "C:\a\_work\1\s\artifacts\obj\Controls.Core\Release\net10.0-windows10.0.20348.0\\output.json"" exited with code 1. [C:\a\_work\1\s\src\Controls\src\Core\Controls.Core.csproj::TargetFramework=net10.0-windows10.0.20348.0]
C:\a\_work\1\s\src\Compatibility\Core\src\Android\CollectionView\ObservableGroupedSource.cs(235,35): error CS1061: 'IDispatcher' does not contain a definition for 'DispatchIfRequired' and no accessible extension method 'DispatchIfRequired' accepting a first argument of type 'IDispatcher' could be found (are you missing a using directive or an assembly reference?) [C:\a\_work\1\s\src\Compatibility\Core\src\Compatibility.csproj::TargetFramework=net10.0-android36.0]
C:\a\_work\1\s\src\Compatibility\Core\src\Android\CollectionView\ObservableItemsSource.cs(94,26): error CS1061: 'IDispatcher' does not contain a definition for 'DispatchIfRequired' and no accessible extension method 'DispatchIfRequired' accepting a first argument of type 'IDispatcher' could be found (are you missing a using directive or an assembly reference?) [C:\a\_work\1\s\src\Compatibility\Core\src\Compatibility.csproj::TargetFramework=net10.0-android36.0]
    10 Error(s)

Could you review it?

@jsuarezruiz I’ve resolved the build errors. Please let me know if any further changes are required.

@PureWeen
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration
Projects
Status: Changes Requested
Development

Successfully merging this pull request may close these issues.

3 participants