简体   繁体   English

如何在调用线程上强制ObserveOn()?

[英]how to force ObserveOn() on calling thread?

I have a reactiveui/rx app. 我有一个reactui / rx应用程序。 Currently, I'm developing it's desktop part, so it's a wpf application. 当前,我正在开发它的桌面部分,因此它是一个wpf应用程序。 I would like to create each window in its separate thread, because of performance reasons. 由于性能原因,我想在其单独的线程中创建每个窗口。

That's why I need ObserveOn to be run on a current thread 这就是为什么我需要ObserveOn在当前线程上运行

someCollection.Changed.Buffer(TimeSpan.FromSeconds(n)).ObserveOn(*should be a link to a current thread*).Subscribe(bufferedItems => {})

also, this code is located in a portable lib, that's why I can't use System.Threading.Thread class 而且,此代码位于可移植的库中,这就是为什么我不能使用System.Threading.Thread类的原因

Is there any workaround? 有什么解决方法吗?

If you can capture the Dispatcher you can then provide that to the DispatcherScheduler . 如果可以捕获Dispatcher ,则可以将其提供给DispatcherScheduler

var currentDispatcher = Dispatcher.CurrentDispatcher;
var scheduler = new DispatcherScheduler(currentDispatcher);

Observable.Empty<int>().ObserveOn(scheduler)....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM