Skip to content

Accessing RxApp.MainThread inside Task.Run block returns default scheduler. #2262

@giard-alexandre

Description

@giard-alexandre

Bug

It seems that, either on newer ReactiveUI versions or specifically in ReactiveUI.Avalonia, when a user calls RxApp.MainThreadScheduler (or the newer RxSchedulers.MainThreadScheduler) from within a TaskRun(_ => CODEHERE) bloc, that MainThreadScheduler is still assigned to DefaultScheduler.Instance instead of the AvaloniaScheduler.

I'm not sure if this is an issue in the latest version of ReactiveUI itself or if it is introduced by the new ReactiveUI.Avalanoia package. I can't test using ReactiveUI 22.1.1 and the old Avalonia.ReactiveUI 11.3.8 package as I get a missing method exception thrown by splat (seems the Avalonia-managed reactiveui package hasn't been updated to use the new splat version).

I can confirm that this was not present in previous versions of ReactiveUI/Avalonia.ReactiveUI combinations.

Which library version?

ReactiveUI: 22.1.1
ReactiveUI.Avalonia: 11.3.0

What are the platform(s), environment(s) and related component version(s)?

Tested on windows 11 and macos Sierra, probably afffects all environments?

What is the use case or problem?

Access RxApp.MainThreadScheduler from inside a Task.Run() block.

What is the expected outcome?

The correct AvaloniaScheduler is referenced.

What is the actual outcome?

DefaultScheduler.Instance is used

What is the stacktrace of the exception(s) if any?

Do you have a code snippet or project that reproduces the problem?

https://github.com/giard-alexandre/ReactiveUI_MainThread_Repro

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions