Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ObserveOnDispatcher not working

I have 2 threads, WPF+PIPE. I register the from the WPF on the pipe rx event. when using ObserveOnDispatcher() the registered handler is not called, when removing the ObserveOnDispatcher() it is called on the pipe thread. Does anyone have ideas why it is not called at all when using ObserveOnDispatcher()?

like image 863
ie1 Avatar asked Feb 24 '23 04:02

ie1


1 Answers

DispatcherObservable.ObserveOnDispatcher takes the dispatcher of the current thread at the time when it is called. If you call it from a background thread, it will look for a dispatcher on that thread (if it has one).

If you want to call back to the UI thread, you'll need to get the IScheduler from Scheduler.Dispatcher while on the UI thread (like at the start of the application) and pass that instance to your background thread. You can then use ObserveOn(dispatcherSchedulerInstance) to schedule back to the UI thread.

like image 140
Richard Szalay Avatar answered Mar 05 '23 22:03

Richard Szalay