ReactiveCommand.Subscribe not running in UI thread?!

434 views
Skip to first unread message

Atle

unread,
Mar 2, 2015, 10:11:44 AM3/2/15
to reacti...@googlegroups.com
Hi!

I thought that subscribing to a ReactiveCommand should invoke the subscription in the UI thread? For some reason it is usually invoked in a worker thread even though the command is invoked in the UI thread.

This is what triggers the command:


in Constructor:

SeriesCollection = new ObservableCollection<IChartSeriesViewModel>();

ReactiveCommand.CreateAsyncTask(async _ =>
{
    ....
    var data = await getDataAsync(); <--- All except this must run in UI
    .... 
    (Create view models from data)
    ....    
    return viewModels;
}

CreateSeries.ObserveOn(RxApp.MainThreadScheduler).Subscribe(x =>
{
    SeriesCollection.Clear(); <------------------- Crash due to invoked by worker thread which is not owner of the SeriesCollection object.
    foreach (var chartSeriesViewModel in x)
        SeriesCollection.Add(chartSeriesViewModel);
    YRange = CalculateYRange(x);
});

Listen to a property changed event of the background model
IDisposable selectedAnalysisSubscription =
                this.WhenAnyValue(x => x.Model.SelectedIdentifierPropertyPair)
                     .ObserveOn(RxApp.MainThreadScheduler)
                     .InvokeCommand(CreateSeries);

How do

Atle

unread,
Mar 3, 2015, 5:40:26 AM3/3/15
to reacti...@googlegroups.com
Seems like the RxApp.MainThreadScheduler is not set up correctly.

Adding this on startup seems to fix the issue:

RxApp.MainThreadScheduler = DispatcherScheduler.Current;
RxApp.TaskpoolScheduler = TaskPoolScheduler.Default;

- Atle

paul....@gmail.com

unread,
Mar 3, 2015, 11:26:10 PM3/3/15
to reacti...@googlegroups.com, reacti...@googlegroups.com
Platform?

Paul



--
You received this message because you are subscribed to the Google Groups "ReactiveUI mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to reactivexaml...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Atle

unread,
Mar 4, 2015, 2:05:31 AM3/4/15
to reacti...@googlegroups.com
Windows WPF compiled from source and strong named due to being a plug-in to another application. The host application seems to be using Rx as well, and I am getting some "different versions" redirect errors to System.Reactive.Windows.Threading. Not sure if this has anything to do with this.

- Atle

paul....@gmail.com

unread,
Mar 9, 2015, 1:36:25 AM3/9/15
to reacti...@googlegroups.com, reacti...@googlegroups.com
I think all of your problems are because of the strong naming, because you didn’t patch this:


Best,
Paul

Vladimir Morozov

unread,
Jun 5, 2015, 9:44:33 AM6/5/15
to reacti...@googlegroups.com
Could you please clarify which patch you're talking about?

Reply all
Reply to author
Forward
0 new messages