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