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

awaiting on an observable

So in the sad days of C# 4.0, I created the following "WorkflowExecutor" class that allowed asynchronous workflows in the GUI thread by hacking into IEnumerable's "yield return" continuations to wait for observables. So the following code would, at…
Dax Fohl
  • 10,654
  • 6
  • 46
  • 90
27
votes
6 answers

Does reactive extensions support rolling buffers?

I'm using reactive extensions to collate data into buffers of 100ms: this.subscription = this.dataService .Where(x => !string.Equals("FOO", x.Key.Source)) .Buffer(TimeSpan.FromMilliseconds(100)) .ObserveOn(this.dispatcherService) …
Kent Boogaart
  • 175,602
  • 35
  • 392
  • 393
27
votes
4 answers

How to expose IObservable properties without using Subject backing field

In this answer to a question about Subject Enigmativity mentioned: as an aside, you should try to avoid using subjects at all. The general rule is that if you're using a subject then you're doing something wrong. I often use subjects as…
Wilka
  • 28,701
  • 14
  • 75
  • 97
26
votes
2 answers

Joining Rx Streams

I'm trying to model an Rx query that is not trivial (to me): In a room there are Men and Women. They enter and leave the room, and while in the room sometimes they change their location. Each man can look at one (or zero) woman at a given…
Omer Mor
  • 5,216
  • 2
  • 34
  • 39
26
votes
4 answers

What do the various ISubject implementations do and when would they be used?

I have a fairly good idea of what the Subject class does and when to use it, but I've just been looking through the language reference on msdn and see there are various other ISubject implementations such…
James Hay
  • 12,580
  • 8
  • 44
  • 67
25
votes
4 answers

RX Subjects - are they to be avoided?

I've had a mini-discussion on the topic in another thread, and would like to have people's input on the "bad" sides of subjects. People who frequent the RX forum know that E.Meijer does not like Subjects. While I have a deepest respect to RX…
Sergey Aldoukhov
  • 22,316
  • 18
  • 72
  • 99
25
votes
4 answers

How to create Observable from function?

I want to call a function (synchronously) and then use its return value as an initial emission (subsequently chaining some other operators on the resulting observable). I want to invoke this function during subscription, so I can't just use…
Titan
  • 2,875
  • 5
  • 23
  • 34
25
votes
6 answers

Write an Rx "RetryAfter" extension method

In the book IntroToRx the author suggest to write a "smart" retry for I/O which retry an I/O request, like a network request, after a period of time. Here is the exact paragraph: A useful extension method to add to your own library might be a…
nverinaud
  • 1,270
  • 14
  • 25
24
votes
6 answers

Creating a weak subscription to an IObservable

What I want to do is ensure that if the only reference to my observer is the observable, it get's garbage collected and stops receiving messages. Say I have a control with a list box on it called Messages and this code behind: //Short lived display…
ForbesLindesay
  • 10,482
  • 3
  • 47
  • 74
24
votes
1 answer

Observable.Generate with TimeSpan selector appears to leak memory [When using a TimeSpan > 15ms]

I am investigating the use of Observable.Generate to create a sequence of results sampled at intervals using the examples from the msdn website as a starting point. The following code WITHOUT a TimeSpan selector does not exhibit a memory…
24
votes
1 answer

How to implement an IObserver with async/await OnNext/OnError/OnCompleted methods?

I'm trying to write an extension method for System.Net.WebSocket that will turn it into an IObserver using Reactive Extensions (Rx.NET). You can see the code below: public static IObserver ToObserver(this WebSocket webSocket,…
24
votes
4 answers

Observable.FromAsync vs Task.ToObservable

Does anyone have a steer on when to use one of these methods over the other. They seem to do the same thing in that they convert from TPL Task to an Observable. Observable.FromAsync appear to support cancellation tokens which might be the subtle…
user630190
  • 1,142
  • 2
  • 11
  • 26
24
votes
1 answer

ReactiveUI (RxUI) vs Reactive Extensions

From http://docs.reactiveui.net/en/index.html : ReactiveUI is a MVVM framework that allows you to use the Reactive Extensions for .NET to create elegant, testable User Interfaces that run on any mobile or desktop platform. Is RxUI somehow…
tower120
  • 5,007
  • 6
  • 40
  • 88
24
votes
5 answers

Real world examples of Rx

Possible Duplicate: Good example of Reactive Extensions Use I've been playing around with the Reactive Extension for a little while now, but mostly limited to handling/composing user driven events within a WPF frontend. It's such a powerful, new…
theburningmonk
  • 15,701
  • 14
  • 61
  • 104
22
votes
6 answers

Guide to System.Reactive.Joins

I'm looking for an introduction/ some documentation of System.Reactive.Joins, which includes the Pattern, Plan, QueryablePattern and QueryablePlan classes. Google doesn't turn up anything ("System.Reactive.Joins"), MSDN has nothing, there are no…
Matthew Finlay
  • 3,354
  • 2
  • 27
  • 32