简体   繁体   中英

how to force ObserveOn() on calling thread?

I have a reactiveui/rx app. Currently, I'm developing it's desktop part, so it's a wpf application. 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

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

Is there any workaround?

If you can capture the Dispatcher you can then provide that to the DispatcherScheduler .

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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