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
33
votes
2 answers

Tricks for debugging with Reactive Extensions?

I'm looking for ideas on how to make RX more easily debuggable. It can be so very difficult to find the point of failure when a source is passed through combiners and throttles and publishes and such. So far I've been doing similar things to what I…
scobi
  • 14,252
  • 13
  • 80
  • 114
33
votes
2 answers

C# .NET Rx- Where is System.Reactive?

I have an intensive Java background so forgive me if I'm overlooking something obvious in C#, but my research is getting me nowhere. I am trying to use the reactive Rx .NET library. The compiler is not complaining about the IObservable but it is…
tmn
  • 11,121
  • 15
  • 56
  • 112
32
votes
5 answers

Reactive Extensions (Rx) + MVVM =?

One of the main examples being used to explain the power of Reactive Extensions (Rx) is combining existing mouse events into a new 'event' representing deltas during mouse drag: var mouseMoves = from mm in mainCanvas.GetMouseMove() …
Jesper Larsen-Ledet
  • 6,625
  • 3
  • 30
  • 42
31
votes
3 answers

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…
irascian
  • 1,945
  • 2
  • 15
  • 9
31
votes
4 answers

How to call back async function from Rx Subscribe?

I would like to call back an async function within an Rx subscription. E.g. like that: public class Consumer { private readonly Service _service = new Service(); public ReplaySubject Results = new ReplaySubject(); …
30
votes
4 answers

Should IObservable be preferred over events when exposing notifications in a library targeting .NET 4+

I have a .NET library which, as part of an Object Model will emit notifications of certain occurrences. It would seem to me that the main pros of events are approachability for beginners (and simplicity in certain consumption contexts) with the main…
Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
30
votes
1 answer

Why the name "Behavior" in BehaviorSubject in RX?

I'm curious, why do you think they used the name "Behavior" for the BehaviorSuject object in Ractive Extensions? note: a behavior subject returns the last value (or the init vaue) as the first value to any subscriber.
Nestor
  • 13,706
  • 11
  • 78
  • 119
30
votes
4 answers

What is LINQ to events a.k.a RX Framework?

What is LINQ to events a.k.a RX Framework aka the Reactive Extensions in .NET 4.0 (but also available as backported versions)? In other words, what is all the stuff in System.Reactive.dll for?
Ahmed Atia
  • 17,848
  • 25
  • 91
  • 133
29
votes
1 answer

How does RxJava doOnError and onErrorReturn work?

I made these unit tests, and the outcome is not what I expected at all: // This one outputs "subscribe.onError" @Test public void observable_doOnError_subscribingToError() throws InterruptedException { Observable obs =…
Nilzor
  • 18,082
  • 22
  • 100
  • 167
29
votes
2 answers

RX vs messaging queues like rabbitmq or zeromq?

I'm quite new to these high level concurrency paradigms, and I've started using the scala RX bindings. So I'm trying to understand how RX differs from messaging queues like RabbitMQ or ZeroMQ? They both appear to use the subscribe/publish paradigm.…
Luciano
  • 2,388
  • 1
  • 22
  • 33
29
votes
4 answers

Advantages of .NET Rx over classic events?

.NET 4.0 beta 2 has introduced the IObservable and IObserver interfaces. What are the advantages compared to classic .NET events? Doesn't this solve the same problem?
Wim Coenen
  • 66,094
  • 13
  • 157
  • 251
28
votes
1 answer

Why does the Task.WhenAny not throw an expected TimeoutException?

Please, observe the following trivial code: class Program { static void Main() { var sw = new Stopwatch(); sw.Start(); try { Task.WhenAny(RunAsync()).GetAwaiter().GetResult(); } …
mark
  • 59,016
  • 79
  • 296
  • 580
28
votes
3 answers

How can I clear the buffer on a ReplaySubject?

How can I clear the buffer on a ReplaySubject? Periodically I need to clear the buffer (as an end of day event in my case) to prevent the ReplaySubject continually growing and eventually eating all the memory. Ideally I want to keep the same…
CodingHero
  • 2,865
  • 6
  • 29
  • 42
28
votes
1 answer

How to handle exceptions thrown by observer's onNext in RxJava?

Consider the following example: Observable.range(1, 10).subscribe(i -> { System.out.println(i); if (i == 5) { throw new RuntimeException("oops!"); } }, Throwable::printStackTrace); This outputs numbers from 1 to 5 and then…
izstas
  • 5,004
  • 3
  • 42
  • 56
28
votes
1 answer

How I can make use of Microsoft Rx Framework to implement Bing Map effectively in WinRT / Windows 8

In my e-commerce application I need to plot my nearby stores in Bing map, And my another requirement is during the time of zooming and paning the map I need to update my stores based on the map centre. So for implementing this I primarily choose the…
StezPet
  • 2,430
  • 2
  • 27
  • 49