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
2
votes
1 answer

How to use RxJava for file parsing and SQL generation?

Most examples of RxJava I see have to do with network calls. I am new to the framework, so I am wondering if using it for something like parallel file parsing makes sense as well. I have a directory of files, whose data I need to parse into SQL…
ZakTaccardi
  • 12,212
  • 15
  • 59
  • 107
2
votes
2 answers

Take N values from observable on each interval

I have an observable which streams a value for each ms. , this is done every 250 ms. ( meaning 250 values in 250 ms (give or take) ). Mock sample code : IObservable> input = from _ in…
eran otzap
  • 12,293
  • 20
  • 84
  • 139
2
votes
3 answers

How to await on IObservable of IObservables?

I have an IObservable of objects, which I want to convert to dictionary of lists asynchronously. Here is my code, where GetSource returns an IObservable: await GetSource(...) .GroupBy(o => o.SiteId) .ToDictionary(g => g.Key, g => g.ToList()) Of…
mark
  • 59,016
  • 79
  • 296
  • 580
2
votes
2 answers

ReactiveCommand not handling observable call as expected

I'm having trouble with the way ReactiveCommand deals with ObserveOn and SubscribeOn. I have an API that returns an observable sequence of strings, and it looks like this : public IObservable GetDocumentObservable(int numParagraphs, int…
enomam
  • 89
  • 5
2
votes
3 answers

C# Reactive Extensions - Subscribe to stream of aggregation

I Have a stream of points and would like to combine each 2 points in order to draw a line . public class MyPoint { public int X { get; set; } public int Y { get; set; } } I am looking for something that would combine the functionality of…
eran otzap
  • 12,293
  • 20
  • 84
  • 139
2
votes
2 answers

Could Reactive Extension capture/detect consecutive cases?

Use this, Rx generates a series of random numbers between 0 and 99. var R = new Random(); var ints = Observable.Interval(TimeSpan.FromSeconds(1)); var RandomNos = ints.Select(i=> R.Next(100)); // was new Random().Next(100) RandomNos.Subscribe(r=>…
Rm558
  • 4,621
  • 3
  • 38
  • 43
2
votes
1 answer

ActionBlock Framework 4 rx alternative

I'm interested in an ActionBlock implementation for Framework 4.0, since there it seems that TPL.Dataflow isn't supported for Framework 4.0. More particularly, I'm interested in the case of the constructor that receives the Func
darkl
  • 569
  • 2
  • 13
2
votes
2 answers

Creating an Observable around sets of continously changing depended observables

The code snippet below is my attempt at creating the following functionality: Create an observable sequence that subscribes to a collection of subjects When one of the subjects in the collection produces a value, the sequence ends, invokes a method…
Oliver Weichhold
  • 10,259
  • 5
  • 45
  • 87
2
votes
2 answers

Observable.Window and .Zip not functioning like I would expect

I'm trying to turn an IEnumerable into an IObservable that delivers its items in chunks one second apart. var spartans = Enumerable.Range(0, 300).ToObservable(); spartans .Window(30) .Zip(Observable.Timer(DateTimeOffset.Now,…
moswald
  • 11,491
  • 7
  • 52
  • 78
2
votes
1 answer

Rx Example not working

I'm trying to follow along with Jonathan Worthington's airport announcement example in An Event-driven and Reactive Future It compiles. The problem: SayGateChange is never called. I'm new to Rx. I must be leaving something out. What I have here is…
toddmo
  • 20,682
  • 14
  • 97
  • 107
2
votes
2 answers

WebClient Timeout takes longer than expected (Using: Rx, Try Catch, Task)

Problem: I inherited WebClient in ExtendedWebClient where I override the WebRequest's timeout property in the GetWebRequest method. If I set it to 100ms, or even 20ms, it always takes up to more than 30 seconds at least. Sometimes it seems to not…
Yves Schelpe
  • 3,343
  • 4
  • 36
  • 69
2
votes
0 answers

RX events produced no more often than

In my win forms application I get data from web service periodically or on user request. It is required, that the web service is queried no more often than every 2 seconds, whereas the timer period is 5 seconds. At the startup the app should also…
Piotr Cierpich
  • 427
  • 2
  • 11
2
votes
1 answer

How do I spoon feed an IObservable from procedural code?

Most sample codes around Reactive Extensions revolves around how you compose logic and operators on the sequence. The parts around Observable generation focus around "FromEventPatter","FromAsynch" etc. IObservable observableHotStatus =…
Tormod
  • 4,551
  • 2
  • 28
  • 50
2
votes
1 answer

Observable.Using( ) cancellation

I have a observable made by the Using helper: var o = Observable.Using( () => { return new MyResource }, res => { return new Observable.Create(observer => ....); }); How can I cancel the observable?…
Vegar
  • 12,828
  • 16
  • 85
  • 151
2
votes
2 answers

Testing Reactive Extensions - How do I use the test scheduler with ToTask()?

I'm having trouble testing reactive code that's consuming a Task based service. In my class under test I consume the task and use ToObservable to do reactive-y things with it. public void Method() { …
Clyde
  • 8,017
  • 11
  • 56
  • 87