Dispatcher Scheduler - Rx

Mik*_*ike 7 c# system.reactive

我们正在使用.NET 3.5并已开始使用Reactive Extensions.我们正在使用与.NET 3.5兼容的system.Reactive(运行时版本:v2.0.50727).

我正在尝试观察调度程序调度程序上的事件,因为我正在使用WPF控件(它是winforms shell,嵌入了WPF主机控件),但我无法在Scheduler类上找到该选项(system.reactive.concurrency.scheduler) .看起来它可以从.NET 4.0开始提供.我的问题是,如何在.NET 3.5中使用它?请注意,调用发生在我的ViewModel中,而不是View.

码:

 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);
Run Code Online (Sandbox Code Playgroud)

谢谢,

-麦克风

Hun*_*ter 9

更新:基于Rx 2.2.4.0.
用于WPF的DispatcherScheduler当前已移至System.Reactive.Windows.Threading命名空间.
使用Nuget包,搜索Rx-WPF以下载包并使用DispatcherScheduler.Current代替Scheduler.Dispatcher


bra*_*ing 5

您应该可以使用http://www.nuget.org/packages/Rx-WinForms/中的RX Winforms扩展库.

this.ObservePropertyChanged(x => x.Queue)
           .ObserveOn(control);
Run Code Online (Sandbox Code Playgroud)

或者如果你已经在正确的线程上.

this.ObservePropertyChanged(x => x.Queue)
           .ObserveOn(SynchronizationContext.Current);
Run Code Online (Sandbox Code Playgroud)


Coo*_*rce 3

我认为你应该能够使用 DispatcherScheduler.Current