ObserveOnDispatcher无法正常工作 [英] ObserveOnDispatcher not working

查看:75
本文介绍了ObserveOnDispatcher无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个线程,WPF + PIPE.我在管道rx事件上从WPF注册.使用ObserveOnDispatcher()时,不会调用已注册的处理程序,而当删除ObserveOnDispatcher()时,将在管道线程上调用该处理程序.有谁知道为什么在使用ObserveOnDispatcher()时根本不调用它?

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()?

推荐答案

ObservableOnDispatcher 在调用当前线程时使用它的调度程序.如果从后台线程调用它,它将在该线程上寻找一个调度程序(如果有).

ObservableOnDispatcher 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).

如果要回调UI线程,则需要在UI线程上从 Scheduler.Dispatcher 获取 IScheduler (例如在应用程序的开头),然后将该实例传递给您的后台线程.然后,您可以使用 ObserveOn(dispatcherSchedulerInstance)安排回UI线程.

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.

这篇关于ObserveOnDispatcher无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆