Good introduction to the .NET Reactive Framework

Viewed 86753

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?

16 Answers

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,

  1. Introduction to Rx
  2. Static and extension methods
  3. Lifetime management – Completing and Unsubscribing
  4. Flow control
  5. Combining multiple IObservable streams
  6. Scheduling and threading
  7. Hot and Cold observables
  8. Testing Rx
  9. 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).

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.

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.

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!!

Related