I have the following simple code, however when the property change is raised the call to WhenAny throws an InvalidOperationException because 'the calling thread cannot access this object because a different thread owns it.'. Sure enough the code is executing on a worker thread. I can't see my code differs from any of the examples I've seen though.
public ReactiveCommand OpenEditor { get; set; }
private bool _EditorOpen;
public bool EditorOpen
{
get { return _EditorOpen; }
set { this.RaiseAndSetIfChanged(x => x.EditorOpen, value); }
}
public MainViewModel()
{
OpenEditor = new ReactiveCommand(this.WhenAny(x => x.EditorOpen, x => !x.Value));
OpenEditor.Subscribe(x => DoSomething());
}
private void DoSomething()
{
EditorOpen = true;
}