Questions tagged [system.reactive]

System.Reactive refers to the Reactive Extensions for .NET, also known as Rx. Rx provides developers with a reactive programming model over the generic IObservable interface, as opposed to the traditional imperative programming model or the other reactive programming models that rely strictly on .NET Events or specific APIs.

A brief introduction

system.reactive refers to the Reactive Extensions (Rx), a library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators. System.Reactive is the root namespace used through the library. Using Rx, developers represent asychronous data streams using LINQ operators, and parameterize the concurrency in the asynchronous data streams using Schedulers. Simply put, Rx = Observables + LINQ + Schedulers.

Whether you are authoring a traditional desktop or web-based application, you have to deal with asynchronous and event-based programming from time to time. Desktop applications have I/O operations and computationally expensive tasks that might take a long time to complete and potentially block other active threads. Furthermore, handling exceptions, cancellation, and synchronization is difficult and error-prone.

Using Rx, you can represent multiple asynchronous data streams (that come from diverse sources, e.g., stock quote, tweets, computer events, web service requests, etc., and subscribe to the event stream using the IObserver<T> interface. The IObservable<T> interface notifies the subscribed IObserver<T> interface whenever an event occurs.

Because observable sequences are data streams, you can query them using standard LINQ query operators implemented by the Observable extension methods. Thus you can filter, project, aggregate, compose and perform time-based operations on multiple events easily by using these standard LINQ operators. In addition, there are a number of other reactive stream specific operators that allow powerful queries to be written. Cancellation, exceptions, and synchronization are also handled gracefully by using the extension methods provided by Rx.

Rx complements and interoperates smoothly with both synchronous data streams (IEnumerable<T>) and single-value asynchronous computations (Task<T>).

Source and further information

The project is actively developed by Microsoft Open Technologies, Inc., in collaboration with a community of open source developers. The source code is hosted on github here.

Additional documentation, video, tutorials and hands-on-labs are available on MSDN, and help and discussions the Rx Forums.

ReactiveX has been ported to many platforms, and information about supported platforms and links to platform specific implementations can be found here.

Related tags

3422 questions
223
votes
16 answers

Good introduction to the .NET Reactive Framework

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…
LBushkin
  • 129,300
  • 32
  • 216
  • 265
130
votes
4 answers

What are the Hot and Cold observables?

I watched the video and I know the general principles - hot happens even when nobody is subscribed, cold happens "on demand". Also, Publish() converts cold to hot and Defer() converts hot to cold. But still, I feel I am missing the details. Here are…
Sergey Aldoukhov
  • 22,316
  • 18
  • 72
  • 99
127
votes
5 answers

Why are Subjects not recommended in .NET Reactive Extensions?

I am currently getting to grips with the Reactive Extensions framework for .NET and I am working my way through the various introduction resources I've found (mainly http://www.introtorx.com) Our application involves a number of hardware interfaces…
Anthony
  • 2,240
  • 4
  • 20
  • 24
114
votes
1 answer

Reactive Extensions bug on Windows Phone

Compiled with VS 2012, with project type WP 8.0 the following code will fail if debugger is not attached. Somehow, if debugger not attached, compiler optimizations ruins the code inside Crash() - see comments in code. Tested on Lumia 1520 (8.1) and…
Yuriy Naydenov
  • 1,875
  • 1
  • 13
  • 31
84
votes
6 answers

Good example of Reactive Extensions Use

I understand the basics of Rx. Where I'm struggling is how you would actually use this beyond academic examples? What are some common, simple real-world scenarios where Rx is a much better solution than what we have today in .NET?
Keith Hill
  • 194,368
  • 42
  • 353
  • 369
77
votes
3 answers

What's the difference between SubscribeOn and ObserveOn

I just discovered SubscribeOn, which makes me wonder if I should be using that instead of ObserveOn. Google took me here and here, but neither have helped me grok the difference: it seems incredibly subtle. (In my context, I've got events 'coming…
Benjol
  • 63,995
  • 54
  • 186
  • 268
70
votes
2 answers

How do Reactive Framework, PLINQ, TPL and Parallel Extensions relate to each other?

At least since the release of .NET 4.0, Microsoft seems to have put a lot of effort in support for parallel and asynchronous programming and it seems a lot of APIs and libraries around this have emerged. Especially the following fancy names are…
bitbonk
  • 48,890
  • 37
  • 186
  • 278
67
votes
2 answers

ObserveOn and SubscribeOn - where the work is being done

Based on reading this question: What's the difference between SubscribeOn and ObserveOn ObserveOn sets where the code is in the Subscribe handler is is executed: stream.Subscribe(_ => { // this code here }); The SubscribeOn method sets which thread…
Cheetah
  • 13,785
  • 31
  • 106
  • 190
60
votes
3 answers

When to use Observable.FromEventPattern rather than Observable.FromEvent?

We've got a client calling off to a TIBCO EMS queue and are wiring up the events like this: var msgConsumer = _session.CreateConsumer(responseQueue); var response = Observable.FromEvent (h =>…
baralong
  • 1,644
  • 1
  • 16
  • 32
53
votes
1 answer

IObservable vs Plain Events or Why Should I use IObservable?

Microsoft introduced the IObservable interface to the BCL with .NET Framework 4, and I thought, "Great, finally, I must use it!" So I dug deep and read posts and documentation and even implemented the pattern. After doing so I've realized that…
Adiel Yaacov
  • 1,401
  • 3
  • 14
  • 24
52
votes
4 answers

Reactive Extension (Rx) tutorial that is up to date

I am quite interested in Reactive Extensions but I cannot find an up to date tutorial. I started with Curing the asynchronous blues with the Reactive Extensions for .NET but it is out of date. I can figure out some changes but I could not get many…
Igor Kulman
  • 16,211
  • 10
  • 57
  • 118
50
votes
5 answers

TPL vs Reactive Framework

When would one choose to use Rx over TPL or are the 2 frameworks orthogonal? From what I understand Rx is primarily intended to provide an abstraction over events and allow composition but it also allows for providing an abstraction over async…
Abhijeet Patel
  • 6,562
  • 8
  • 50
  • 93
48
votes
3 answers

What is the conceptual difference between SynchronizationContext and TaskScheduler

Stephen Toub blogged that Both SynchronizationContext and TaskScheduler are abstractions that represent a “scheduler”, something that you give some work to, and it determines when and where to run that work. There are many different forms of…
47
votes
1 answer

What are the default Schedulers for each observable operator?

This page on MSDN states that If you do not use the overload which takes a scheduler as an argument, Rx will pick a default scheduler by using the principle of least concurrency. This means that the scheduler which introduces the least amount of…
Alex
  • 7,639
  • 3
  • 45
  • 58
45
votes
1 answer

SignalR vs. Reactive Extensions

Is SignalR the same thing is Reactive Extensions? Can you explain why or why not?
Mike Flynn
  • 22,342
  • 54
  • 182
  • 341
1
2 3
99 100