How can I dispatch an PropertyChanged event from a subscription to an Interval based IObservable

Posted by James Hay on Stack Overflow See other posts from Stack Overflow or by James Hay
Published on 2010-04-07T10:30:10Z Indexed on 2010/04/07 10:33 UTC
Read the original article Hit count: 481

I'm getting an 'UnauthorizedAccesExpection - Invalid cross-thread access' exception when I try to raise a PropertyChanged event from within a subscription to an IObservable collection created through Observable.Interval().

With my limited threading knowledge I'm assuming that the interval is happening on some other thread while the event wants to happen on the UI thread??? An explanation of the problem would be very useful.

The code looks a little like:

var subscriber = Observable.Interval(TimeSpan.FromSeconds(1))
                .Subscribe(x =>
                {
                    Prop = x; // setting property raises a PropertyChanged event
                });

Any solutions?

© Stack Overflow or respective owner

Related posts about rx

Related posts about reactive-extensions