Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rx for .NET - What happened to Scheduler.Dispatcher?

I'm trying to work through Dan Sullivan's Rx Extensions training course on PluralSight. It's excellent stuff but unfortunately Rx seems to have already been changed, even though the course was only published a month ago.

Most of the changes are trivial to work out (change from three dlls to a single dll, change in namespaces used etc) but I'm struggling to understand what I should use in place of Scheduler.Dispatcher in Dan's example. I can't see anything obvious in the properties that are available in the Scheduler.

Here's the code I'm trying to get working with the (refactored?) Rx library (the currenly stable version v1.0.10605)

var query = from number in Enumerable.Range(1, 25) select StringWait(number.ToString()); var observableQuery = query.ToObservable(Scheduler.ThreadPool); observableQuery.ObserveOn(Scheduler**.Dispatcher**).Subscribe(n => Results.AppendText(string.Format("{0}\n", n))); 

What should I be using to invoke the Observer code (Results.AppendText) on the original Dispatcher thread?

like image 280
irascian Avatar asked Jun 26 '11 08:06

irascian


2 Answers

The DispatcherScheduler has been moved to the System.Reactive.Windows.Threading assembly. If you are using NuGet, it's in Rx-WPF

like image 119
Richard Szalay Avatar answered Sep 20 '22 07:09

Richard Szalay


As of 2016-11-25, the reference is RX-XAML.

Unfortunately, Microsoft delisted RX v2.2.5 in favour of RX v3.1.0, which is fully cross platform. However, the cross platform libraries do not support WPF. This means that it is now difficult to find the NuGet package which works with WPF.

To work around this, if you are using WPF + .NET 4.5, install any NuGet package with a dependency on RX-XAML. For example, reactiveui-blend depends on RX-XAML v2.2.5, so this will now work:

setClipboard.ObserveOnDispatcher().Subscribe(o => {     ... }); 
like image 28
Contango Avatar answered Sep 22 '22 07:09

Contango