nuka_cola nuka_cola - 1 month ago 11
Android Question

Update view - Reactive Extensions

I've got following code:


Observable.Interval(TimeSpan.FromMilliseconds(2500)).SubscribeOn(XXX).ObserveOn(YYY).Subscribe(
t => SendCounter(t),
e => HandleException(e));


Where XXX, YYY are
Schedulers
.

Inside SendCounter(t) I set a text with t value.

The problem is that when I run the code I got this error:

'only the original thread that created a view hierarchy can touch its views'


I'm using this component: https://components.xamarin.com/view/rxforxamarin

Answer Source
var uiThread = SynchronizationContext.Current;

Observable
    .Interval(TimeSpan.FromMilliseconds(2500))
    .SubscribeOn(XXX)
    .ObserveOn(uiThread)
    .Subscribe( t => SendCounter(t), e => HandleException(e));