Skip to content

fix(wpf): restore WaitForDispatcherScheduler for WpfMainThreadSchedul… - #4466

Closed
Pranay-Kumar-02 wants to merge 1 commit into
reactiveui:mainfrom
Pranay-Kumar-02:fix/wpf-thread-error-4456
Closed

Pranay-Kumar-02 wants to merge 1 commit into
reactiveui:mainfrom
Pranay-Kumar-02:fix/wpf-thread-error-4456

Conversation

@Pranay-Kumar-02

Copy link
Copy Markdown

Summary

Fixes the WPF main-thread scheduling issue reported in #4456.

In v24, WpfMainThreadScheduler could resolve to a dispatcher associated with the wrong thread. As a result, work scheduled through RxSchedulers.MainThreadScheduler could execute outside the WPF UI thread and cause CollectionView thread-access exceptions when updating UI-bound collections.

Changes

  • Restore WaitForDispatcherScheduler for WpfMainThreadScheduler.
  • Resolve the WPF application's dispatcher through Application.Current.Dispatcher.
  • Preserve an STA fallback for WPF test/headless scenarios.
  • Add regression tests for background-thread scheduling and ObservableCollection updates.
  • Ensure the tests use the actual application dispatcher to avoid cross-test STA dispatcher issues.

Breaking changes

None.

Verification

  • Reproduced the original WPF threading failure before the fix.
  • Verified that the fixed scheduler marshals background work to the WPF dispatcher.
  • Verified the end-to-end WhenAnyValue -> Throttle -> ObserveOn -> ObservableCollection.Add scenario completes without the original NotSupportedException.
  • The full repository dotnet test suite could not be run locally because the .NET SDK is not installed in the local environment; CI should provide the official test-suite verification.

Notes for reviewers

The production change is limited to WpfMainThreadScheduler, with regression coverage added for the reported threading scenario. The tests explicitly target the application's dispatcher rather than assuming the TUnit test thread owns Application.Current.Dispatcher.

@glennawatson

glennawatson commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

Thanks I think this fix needs to go into ReactiveUI.Primitives not this project. That's where the scheduler lives.

@glennawatson

Copy link
Copy Markdown
Contributor

I'm happy to port the fix across at some point in the next couple day, then release and fix. Thanks for the contribution again.

@Pranay-Kumar-02

Copy link
Copy Markdown
Author

Thanks for reviewing this and for the clarification! Glad the investigation helped identify the correct location for the fix. I appreciate you porting it over and getting it into the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants