Mike
Mike

Reputation: 3284

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

Upvotes: 6

Views: 7076

Answers (3)

Hunter
Hunter

Reputation: 2470

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

Upvotes: 8

bradgonesurfing
bradgonesurfing

Reputation: 32162

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);

Upvotes: 5

Cookingsource
Cookingsource

Reputation: 101

I think you should be able to use DispatcherScheduler.Current

Upvotes: 3

Related Questions