Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dispatcher Scheduler - Rx

We are using .NET 3.5 and has started using Reactive Extensions. We are using system.Reactive (Runtime Version:v2.0.50727) which is compatible for .NET 3.5.

I'm trying to observe an event on the dispatcher scheduler since I'm using WPF controls(it's winforms shell, with WPF host control embedded), however I could not spot that option on Scheduler class(system.reactive.concurrency.scheduler). Looks like its available from .NET 4.0 onwards. My question is, how do I get this working in .NET 3.5? Note that the call is happening inside my ViewModel and not View.

Code:

 this.ObservePropertyChanged(x => x.Queue)
               //I cant find scheduler dispatcher option, 
               //there are other options such as current, imeediete, new etc.
               .ObserveOn(Scheduler.Dispatcher)
                .Subscribe(RefreshQueues);

Thanks,

-Mike

like image 907
Mike Avatar asked Sep 23 '13 10:09

Mike


2 Answers

Update: based on Rx 2.2.4.0
DispatcherScheduler for WPF is currently moved into System.Reactive.Windows.Threading namespace.
Using Nuget package, search for Rx-WPF to download the package and use DispatcherScheduler.Current in place of Scheduler.Dispatcher

like image 106
Hunter Avatar answered Oct 26 '22 17:10

Hunter


You should be able to do with the RX Winforms extension library from http://www.nuget.org/packages/Rx-WinForms/

this.ObservePropertyChanged(x => x.Queue)
           .ObserveOn(control);

or if you are on the correct thread already.

this.ObservePropertyChanged(x => x.Queue)
           .ObserveOn(SynchronizationContext.Current);
like image 25
bradgonesurfing Avatar answered Oct 26 '22 18:10

bradgonesurfing