I am trying to implement a simple Observer pattern using the .net Observable class. I have a code that looks like this:
Observable.FromEventPattern<PropertyChangedEventArgs>( Instance.User, "PropertyChanged") .Where(e => e.EventArgs.PropertyName == "FirstName") .ObserveOn(Scheduler.ThreadPool) .Subscribe(search => OnFirstNameChanged(search.EventArgs)); Observable.FromEventPattern<PropertyChangedEventArgs>( Instance.User, "PropertyChanged") .Where(e => e.EventArgs.PropertyName == "LastName") .ObserveOn(Scheduler.ThreadPool) .Subscribe(search => OnLastNameChanged(search.EventArgs));
I want the watchers to run in the background thread, but I want them all to work on the same background thread (for our real implementation, it will be too difficult for each listener to use a different thread).
i.e. I want all OnXXXChanged logic OnXXXChanged execute in a thread other than the user interface thread, but instead of Observing to the entire thread pool, I want to make sure that they work in the correct order, in the same thread.
How should I change this above?
Also, in some related post, are there any good examples of examples using the Observable class to implement this pattern?
source share