Hi!
I have a Reactive command which reads a bunch of data and tries to create SciChart renderable series. The SciChart classes must be created in the UI thread. I invoke the command using:
this.WhenAnyValue(x => x.SelectedAnalysis)
.Throttle(TimeSpan.FromSeconds(1), RxApp.MainThreadScheduler)
.ObserveOn(RxApp.MainThreadScheduler)
.InvokeCommand(this, x => x.CreateSeries);
However, the command is not always invoked on the main thread. Especially if the SelectedAnalysis property is changed multiple times within a second:
CreateSeries = ReactiveCommand.CreateAsyncTask(
async _ =>
{
IScoreAnalysisSetup setup = ActiveSetup;
Tuple<ScoreAnalysisIdentifier, ScoreAnalysisProperty> selectedAnalysis = SelectedAnalysis;
if (setup == null || selectedAnalysis == null)
return;
PlotData truthData = await CreateTruthSeriesAsync(setup, selectedAnalysis);
IList<PlotData> plotDatas = new List<PlotData>();
plotDatas.Add(truthData);
STA crash-->var chartViewModels = plotDatas.Select(CreateIncludedTruthSeries).ToList();
SetSeriesCollection(chartViewModels);
});
What am I doing wrong? I have tried returning the PlotData list from the command and subscribe like this:
CreateSeries.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(x =>
{
if (x == null)
{
SetSeriesCollection();
return;
}
var chartViewModels = x.Select(CreateIncludedTruthSeries).ToList();
SetSeriesCollection(chartViewModels);
});
However, this does not help at all. Still things are being invoked on a background thread.
Sincerely
Atle