Version v1.0.1062.0 Other versions
Preface PART 1 PART 2 PART 3 PART 4 Appendix
Getting started Sequence basics Taming the sequence Concurrency
Lee Campbell
Introduction to Rx
Kindle edition


Reactive programming is not a new concept. I remember studying my first Event Driven module for Visual Basic 5 in 2000. Even then the technology (Visual Basic 5) was already considered somewhat dated. Long before VB5 and the turn of the millennium, we have seen languages supporting events. Over time languages like Smalltalk, Delphi and the .NET languages have popularized reactive or event-driven programming paradigms. This not to say that events are passé: current trends such as CEP (Complex Event Processing), CQRS (Command Query Responsibility Segregation) and rich immersive GUIs, all have events as a fundamental part of their makeup.

The event driven paradigm allows for code to be invoked without the need for breaking encapsulation or applying expensive polling techniques. This is commonly implemented with the Observer pattern, events exposed directly in the language (e.g. C#) or other forms of callback via delegate registration. The Reactive Extensions extend the callback metaphor with LINQ to enable querying sequences of events and managing concurrency.

The Reactive Extensions are effectively a library of implementations of the IObservable<T> and IObserver<T> interfaces for .NET, Silverlight and Windows Phone 7. The libraries are also available in JavaScript. As a dynamic language, JavaScript had no need for the 2 interfaces so the JavaScript implementation could have been written long before .NET 4 was released. This book will introduce Rx via C#. Users of VB.NET, F# and other .NET languages hopefully will be able to extract the concepts and translate them to their particular language. JavaScript users should be able to gather the concepts from this book and apply them to their language. JavaScript users may however find some features are not supported, and some concepts, such as scheduling do not transcend platforms.

As Rx is just a library, the team at Microsoft delivering Rx was able to isolate themselves from the release schedule of the .NET Framework. This proved important as the libraries saw fairly constant evolution since late 2009 through to their official release in mid 2011. This evolution has been largely enabled by the openness of the team and their ability to take onboard criticisms, suggestions and feature requests from the brave community of pre-release users.

While Rx is just a library, it is a significant and bold move forward for the team at Microsoft and for any consumers of the library. Rx will change the way you design and build software.

  1. The way that it tackles the Observer pattern is a divorce from .NET events toward a Java-style interface pattern but far more refined.
  2. The way it tackles concurrency is quite a shift how many .NET developers would have done it before.
  3. The number of (extension) methods in the library is huge.
  4. The way in which it integrates with LINQ to leverage LINQ's composability & declarative style, makes Rx very usable and discoverable to those already familiar with LINQ and IEnumerable<T>.
  5. The way it can help any .NET developer that works with event driven and/or asynchronous programs. Developers of Rich Clients, Web Clients and Services alike can all benefit from Rx.
  6. The future plans seem even grander, but that is a different book for some time in the future :-)

This book aims to teach you:

The best way to learn Rx is to use it. Reading the theory from this book will only help you be familiar with Rx, but will not really enable you to fully understand Rx. You can download the latest version of Rx from the Microsoft Data Developer site ( or if you use NuGet you can just download Rx via that.

My experience with Rx is straight from the trenches. I worked on a team of exceptional developers on a project that was an early adopter of Rx (late 2009). The project was a financial services application that started off life as a Silverlight project then expanded into an integration project. We used Rx everywhere; client side in Silverlight 3/4, and server side in .NET 3.5/4.0. We used Rx eagerly and sometimes too eagerly. We were past leading edge, we were bleeding edge. We were finding bugs in the early releases and posting proposed fixes to the guys at Microsoft. We were constantly updating to the latest version. It cost the project to be early adopters, but in time the payment was worth it. Rx allowed us to massively simplify an application that was inherently asynchronous, highly concurrent and targeted low latencies. Similar workflows that I had written in previous projects were pages of code long; now with Rx were several lines of LINQ. Trying to test asynchronous code on clients (WPF/Win Forms/Silverlight) was a constant pain, but Rx solved that too. Today if you ask a question on the Rx Forums, you will most likely be answered by someone from that team (or Dave Sexton).


I would like to take this quick pause to recognize the people that made this book possible. First is my poor wife for losing a husband to a dark room for several months. Her understanding and tolerance is much appreciated. To my old team "Alpha Alumni"; every developer on that team has helped me in some way to better myself as a developer. Specific mention goes to James Miles, Matt Barrett, John Marks, Duncan Mole, Cathal Golden, Keith Woods, Ray Booysen & Olivier DeHeurles for all the deep dive sessions, emails, forum banter, BBM exchanges, lunch breaks and pub sessions spent trying to get our heads around Rx. To Matt Davey for being brave enough to support us in using Rx back in 2009. Finally to the team at Microsoft that did the hard work and brought us Rx; Jeffery Van Gogh, Wes Dyer, Erik Meijer & Bart De Smet. Extra special mention to Bart, there is just something about the content that Bart produces that clicks with me.

It is my intention that from the experiences both good and bad, I can help speed up your understanding of Rx and lower that barrier to entry to using Rx. This will be a progressive step-by-step approach. It may seem slow in places, but the fundamentals are so important to have a firm grasp on the powerful features. I hope you will have the patience to join me all the way to the end.

The content of this book was originally posted as a series of blog posts at and has proved popular enough that I thought it warranted being reproduced as an e-book. As the content of the blog was free, so too this e-book is free.

The version that this book has been written against is the .Net 4.0 targeted Rx assemblies version 1.0.10621.0 (NuGet: Rx-Main v1.0.11226).

So, fire up Visual Studio and let's get started.

Moving on to : PART 1 - Getting started>>