Skip to content
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

[BUG] ReactiveCommand not trigger #2169

Closed
zy97 opened this issue Sep 17, 2019 · 8 comments
Closed

[BUG] ReactiveCommand not trigger #2169

zy97 opened this issue Sep 17, 2019 · 8 comments
Labels

Comments

@zy97
Copy link

zy97 commented Sep 17, 2019

Describe the bug

When using ReactiveCommand.CreateFromTask and specifying its outputSchedule as TaskpoolScheduler, it is normal at version 9.22.1, but later, there will be no reaction when triggered once

Steps To Reproduce

Expected behavior

Screenshots

Environment

  • OS: WPF
  • Version
  • Device:

Additional context

@zy97 zy97 added the bug label Sep 17, 2019
@open-collective-bot
Copy link

open-collective-bot bot commented Sep 17, 2019

Hey @zy97 👋,

Thank you for opening an issue. We will get back to you as soon as we can. Also, check out our Open Collective and consider contributing financially.

https://opencollective.com/reactiveui

PS.: We offer priority support for all financial contributors. Don't forget to add priority label once you start contributing 😄

An advanced, composable, functional reactive model-view-viewmodel framework for all .NET platforms!

@trucksmart
Copy link
Contributor

I can confirm this isn't working properly unless this is by design. See the attached project:
TestReactiveCommandCreateFromTask.zip

Clicking randomize only works the first time even though we are observing the changes on the main thread scheduler (ToProperty).

@trucksmart
Copy link
Contributor

After more investigation the execution fails on these lines:
ReactiveCommand.cs line 670
ReactiveCommandBase.cs line 197

With this error:

System.InvalidOperationException: 'The calling thread cannot access this object because a different thread owns it.'

The simple fix would be to add ObserveOn(RxApp.MainThreadScheduler) before the OnCanExecuteChanged subscription but I'm not sure if that's desirable? What do you think @glennawatson ?

@glennawatson
Copy link
Contributor

My only concern would be platforms other than WPF which might not care about main thread schedulers. Seems a reasonable thing though off the top of my head.

Want to do a change and see how the unit tests go?

@trucksmart
Copy link
Contributor

My only concern would be platforms other than WPF which might not care about main thread schedulers. Seems a reasonable thing though off the top of my head.

Want to do a change and see how the unit tests go?

It breaks the tests. As an example the output of this test is 3 instead of 2. I'm going to do some digging.

@cabauman
Copy link
Contributor

cabauman commented Aug 16, 2020

I was looking into this and I confirmed your findings (same issue with Android).

But may I ask for an example use case where someone would want to specify the output scheduler as TaskPoolScheduler? It doesn't make the command execute on said scheduler; it just outputs the results on the scheduler. So it seems like the default RxApp. MainThreadScheduler would suit your needs since you mentioned you're observing on the main thread via ToProperty anyways.

With that said though, your proposed fix of adding ObserveOn(RxApp.MainThreadScheduler) works and the unit tests now pass thanks to a recent fix.

@ChrisPulman
Copy link
Member

#2849 should have fixed this so closing

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants