ChatGPT解决这个技术问题 Extra ChatGPT

Good introduction to the .NET Reactive Framework [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it. Closed 8 years ago. Improve this question

Aside from the Microsoft documentation, is there a good introduction and tutorial to the Microsoft Reactive (Rx) framework?

Also, what is a good example (with code) that Reactive makes easier of a programming problem that is challenging to solve using conventional asynchronous coding techniques?

I keep looking - I'll need to see a lot of examples before I have a good idea what it's best used for.
I built a small demo of live Bing search in WPF with Rx : blog.andrei.rinea.ro/2013/06/01/…
I answer exactly this question in a series of posts on my blog: rehansaeed.co.uk/reactive-extensions-part1-replacing-events

C
C2H6O

UPDATE: The blog posts below have been superseded by my online book www.IntroToRx.com. It is a comprehensive 19 chapter book available for free. You can browse it on the web, or download the mobi version for your kindle. You can also get it direct from Amazon for a tiny fee (~99c / 77p). If the book doesn't meet your needs or expectations, let me (the Author) know and we will do better for v2.

Thanks for the link to the Hot/Cold post. This is only one part of the full series,

Introduction to Rx Static and extension methods Lifetime management – Completing and Unsubscribing Flow control Combining multiple IObservable streams Scheduling and threading Hot and Cold observables Testing Rx Buffer, Window, Join and Group Join

I will keep updating this blog with more Rx introductory stuff.

For more advanced stuff you want to go to the Rx Forum (MSDN).


I've been dragging my feet learning about Rx because all of the learning materials are in the form of videos. +1 for providing this text-based resource.
Enumerate this link is dead.
Long live Enumerate this link
I work with James (EnumerateThis) and he just hasn't touched it in years. He doesn't seem to have the time or appetite to revive it
b
bernhof

Here's a wiki site with lots of code examples demonstrating how to use different features of the .NET Rx framework: http://rxwiki.wikidot.com/101samples

I found this to be the most comprehensive site out there, and the one that's quickest to get started with.


So far as I can tell this wiki doesn't so much as tell you which reference to include. Which is rather...frustrating.
umm just add the dlls and open object explorer and search for the class. of course the right click context menu in Visual studio helps too
S
Summer-Time

MSDN Site for Rx-Framework

For a Developer going deeper, the Source Code

Cool Austrian keynote about Rx

This is the best I have seen: DevCamp 2010 Keynote - Rx: Curing your asynchronous programming blues

Some interesting Videos on Channel 9

Kim Hamilton and Wes Dyer: Inside .NET Rx and IObservable/IObserver in the BCL (VS 2010)

An interview with the creator from Rx: Expert to Expert: Brian Beckman and Erik Meijer - Inside the .NET Reactive Framework (Rx)

An introduction from the creator of Rx

E2E: Erik Meijer and Wes Dyer - Reactive Framework (Rx) Under the Hood 1 of 2

E2E: Erik Meijer and Wes Dyer - Reactive Framework (Rx) Under the Hood 2 of 2

An Codeproject Article

Another course first blog with links (new)


+1 Highly recommend these videos, I learned a LOT, also check out some of Bart De Smet 's videos on IQueryable and IQbservable, You get a better understand of the insides of Rx.
The complete samples project for the "DevCamp 2010 keynote" video is here: bartdesmet.net/download/Rx40Samples.zip
B
Benjol

Here's an example of something that is easy to do with reactive programming, but messy (if not challenging) with classic events, it draws lines while the mouse button is down. It is readable, there is no explicit state handling:

var pen = new Pen(Color.Red, 3);
var graphics = this.CreateGraphics();

var mouseMoveWhileDown = 
    from md in this.GetMouseDown()
    from mv in this.GetMouseMove().Until(this.GetMouseUp())
    select new Point(mv.X, mv.Y);

mouseMoveWhileDown
    .Pairwise()
    .Subscribe(tup => graphics.DrawLine(pen, tup.Item1, tup.Item2)); 

(I must confess that in that example, Pairwise() is home-grown...)

The most important thing about IObservable is that it is 'composable', just like IEnumerable.

I thouroughly recommend the video mentioned in another answer. In fact there are several different videos on the subject on Channel9:


Where does .Until come from, I can never use it, I must be missing a reference
@TimothyP, I think it might be a throwback to an older version. That or I wrote one myself (I was playing with implementing IObservable extension methods at the time). From what I can see, the latest version of reactive extensions has a method called TakeUntil, which looks like a good fit.
This is an awesome example that shows the spirit of Rx. Thanks.
Can you share the implementation of Pairwise()?
@blaster, how about this implementation: var pairwise = source.Zip(source.Skip(1), (x, y) => new Tuple(x, y)).
O
Oliver

Once you have gone through some of the basic stuff including the HandsOnLab make sure you check out Lee Campbell's Hot and Cold Observables which took some of the arcane mystery out of Rx for me :)


C
Colonel Panic

Bizarrely, the Reactive Extensions homepage links to a dozen videos and blogs but forgets to link to the comprehensive official reference documentation. That's a crying shame, if you know the team, please ask them to fix their website!

http://msdn.microsoft.com/en-us/library/hh242985(v=vs.103).aspx

http://msdn.microsoft.com/en-us/library/hh242986(v=vs.103).aspx

http://msdn.microsoft.com/en-us/library/system.reactive.linq.observable(v=VS.103).aspx


P
Peter Mortensen

You may find this series of articles (there are four) about reactive LINQ useful: Reactive programming (II.) - Introducing Reactive LINQ.

He has an example of writing a game using it, so it should hopefully be what you are looking for.


P
Peter Mortensen

I also found Introducing the Reactive Framework Part I on CodeBetter.com. There is a sequel to the first part on the same site.

I hope this will help you.


O
Omer Raviv

Play with Rx Sandbox to get a very intuitive view of what the different combinators mean. This is the best learning tool I've seen.


a
amazedsaint

Go through these articles, and in particular, download the related source code and play with it.

Part I - System.Reactive or the .NET Reactive Extensions (Rx) – Concepts and First Look

Part II - LINQ To Events - More on .NET Reactive Extensions (Rx)

Part III - LINQ To Events - Generating GetEventName() Wrapper Methods using T4 Text Templates

Trust this will help


P
Peter Mortensen

To answer the second question, here is a problem that can benefit a lot from Rx. It's called "Get rich quick".

You have developed a game by the same name and it's selling pretty well. But it is available only at your stores for wholesale. To make the cash processing easier, you have a conveyor belt which flows towards you.

(Please feel free to change the story above :) )

Sales people place bound wads of cash on it with no labels indicating the amount and type of bills in the wad. Your job is to sort and count the money. Later on, when you get more money, you can hire others to help you.

In this case, the source is an asynchronous source of wads of cash (Producer). Your employees and suppliers expect money, but you have to consume the wads, unpack them and use your custom business logic to repackage as appropriate to pay them.

The sales people are running on their own thread, so that they don't have to wait for you to count what they throw on the belt. Your time is best utilized if you are told when more money is available to count, until then you can do other work.

You could represent each wad by a byte[].

This is a fairly common real world situation; when you retrieve any resource [for example, webpages for search engines, images or videos] on a network or data from peripherals, you get them in chunks of bytes (possibly with headers). In a single thread, or in a multi-thread environment that is too difficult to work with, you tend to aggregate and process them. Not any more!!


this is just some producers (sales people) calling OnNext on the same IObserver and then the consumer subscribing but ensuring that the it is Observing on a different thread to where it is being produced(OnNext).
S
Shane Castle

Jesse Liberty has a book out, published Oct 2011:

Amazon.com: Programming Reactive Extensions and LINQ

And there's the RxWorkshop videos on Channel9:

Channel9: RxWorkshop


M
Matt Breckon

Does your "excluding Microsoft documentation" clause extend to the videos on Channel 9?

From the creator of the reactive framework Erik Meijer: - Expert to Expert: Brian Beckman and Erik Meijer - Inside the .NET Reactive Framework (Rx)

Brand new: Getting Started with Rx Extensions for .NET


g
gideon

In addition to Andreas Hoffmann's links (found them very helpful when I was learning Rx)

Here are some of Bart De Smet (a VERY smart guy who explains things really well) Videos:

Kinda a run through of Rx:
Rx - Curing your Asynchronous Programming Blues

Some gory insides + some philosophy, these videos are really enlightening:
Min LINQ - The essence of LINQ
(The above video deals with how LINQ kinda relates to other things, Like Rx)

Observations on IQbservable - The Dual of IQueryable


P
Peter Mortensen

DEVHOL202 – Curing the asynchronous blues with the Reactive Extensions for .NET (PDF, 2 MB) is the best lab/tutorial I've seen so far. It guides you through the basics of the library, so that you can build and design on what you've learned.

There is also a JavaScript version. Search Google for "Reactive Extensions Hands on Lab".


P
Peter Mortensen

I liked Introduction to Rx Part 1 - Key types, and it showed the key features.


this series evolved into online book at introtorx.com