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 Observable does not propagate results #3942

Open
Micha-kun opened this issue Jan 17, 2025 · 5 comments
Open

[Bug]: ReactiveCommand Observable does not propagate results #3942

Micha-kun opened this issue Jan 17, 2025 · 5 comments
Labels

Comments

@Micha-kun
Copy link
Contributor

Describe the bug 🐞

I don't know if it's a bug or something I'm doing wrong...

I have a ReactiveCommand that returns an IEnumerable and I'm trying to chain those results to another pipeline, like in this code example:

this.WhenActivated(
    d =>
    {
       this.GetDataCommand.Do(_ => { }).Subscribe().DisposeWith(d);
       this.GetDataCommand.Execute().Subscribe().DisposeWith(d);
    });

....

[ReactiveCommand]
private Task<IEnumerable> GetData(CancellationToken ct){
     return Task.FromResult([]);
}

The GetDataCommand RC is a Task method with Unit as Input and IEnumerable as Output. this.GetDataCommand.Execute() really executes succesfully, but, unexpectedly, the Do method attached before to the command never executes after. I tried to wrap command inside this.WhenAnyObservable() without exit. What I'm doing wrong? At first I thought it was because I was using ReactiveUI.SourceGenerators, but I tried with plain ReactiveCommands with the same results. I tried removing those DisposeWith(d) too and nothing changed.

My app is a Winforms app in .Net 8. ViewModel is in a Class Library only for ViewModels.

Step to reproduce

1 - Test my sample.

Reproduction repository

https://github.com/reactiveui/ReactiveUI

Expected behavior

Do/Select/Subscribe code executing

Screenshots 🖼️

No response

IDE

Visual Studio 2022

Operating system

Windows

Version

11

Device

PC

ReactiveUI Version

20.1.63

Additional information ℹ️

No response

@Micha-kun Micha-kun added the bug label Jan 17, 2025
@ChrisPulman
Copy link
Member

@Micha-kun please could you provide a Repo with the code so that we can assist you, I have tried the code you have shown and this works as expected.

@Micha-kun
Copy link
Contributor Author

Micha-kun commented Jan 18, 2025

I was trying too in a clean app and cannot replicate too, so I was wondering if the problem comes with RxApp initialization... Because in my app i'm using Splat.Microsoft.Extensions.DependencyInjection to initialize Splat with Generic Host but there is a problem because i'm using https://github.com/alex-oswald/WindowsFormsLifetime for a better integration of Winforms hosting into Generic Host and it generates a problem:

During service initialization, it's called under one thread but WindowsFormsLifetime, after that, creates a new thread for Winforms form in a new STA thread. Doing that, because Splat initialization is done in another thread, RxApp.MainThread is using a wrong "UI thread", not the one WindowsFormsLifetime creates. What I did to fix that is replace it when it calls the main form with a ControlScheduler, and it's fine but, is there a way to regenerate it using ReactiveUI api?

Thanks

GitHub
Windows Forms hosting extensions for the .NET Generic Host - alex-oswald/WindowsFormsLifetime

@ChrisPulman
Copy link
Member

@Micha-kun
Copy link
Contributor Author

I didn't know those extensions, thanks! I need to investigate them 👍

@ChrisPulman
Copy link
Member

How did you get on with the Reactivemarbles.Extensions.Hosting packages?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants