4imble
4imble

Reputation: 14416

RX threadding issues in WinRT

I have some simple code:

var timer =  Observable.Timer(TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(1)).Timestamp();

 //timer.Subscribe(x => timerTb.Text = x.Value.ToString());
 timer.Subscribe(x => Debug.WriteLine(x.Value));

And a textbox on the view called timerTb. I am trying to get the commented out line to work without it shouting about marshalling issues.

From what i can find out i should be using timer.ObserveOnDispatcher().Subscribe(... But i do not have access to this method, nor do i have access to the CoreDispatcherScheduler dispite referencing "System.Reactive.Linq;"

I am running RX 2.0.20304.0

Any ideas?

Upvotes: 1

Views: 324

Answers (2)

4imble
4imble

Reputation: 14416

I managed to get it working.

Silly rookie mistake CoreDispatcherScheduler was in : System.Reactive.Windows.Threading

Once i referenced that i got ObserveOnDispatcher() and this worked:

var timer = Observable.Timer(TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(1)).Timestamp();

timer.ObserveOnDispatcher().Subscribe(x => timerTb.Text = x.Value.ToString());

Upvotes: 2

Ana Betts
Ana Betts

Reputation: 74654

Put your timer on the UI thread:

Observable.Timer(TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(1), CoreDispatcherScheduler.Instance)
    .Timestamp();

Upvotes: 1

Related Questions