Reactive Extensions for .NET 4.5
First up is Rx support for ExceptionDispatchInfo. In previous versions of .NET exceptions were expected to be caught on the same thread that they were thrown on. Libraries that needed to move them to another thread passed them as a field to a marshaled callback where they were then wrapped with a generic exception. This new exception would have to be unwound to see the real error underneath.
The ExceptionDispatchInfo.Capture method is used to capture an exception. It is then rethrown on the correct thread using ExceptionDispatchInfo.Throw. The stack trace includes frames from both the new and original location, with the text “End of stack trace from previous location where exception was thrown” separating the two.
When Reactive Extensions was created they could not take a dependency on Task<T>. The Task Parallel Library was simply not ready yet and even today many platforms such as Silverlight still don’t support the TPL. As a work-around the Rx libraries were instead built on top of .NET’s original async pattern. Instead observables were created via the Observable.FromAsyncPattern method.
With the async/await support in C# 5 and VB 11 being built on top of tasks, the various platforms are now intending to fully support the Task Parallel Library. This is allowing the Rx project to finally build observables directly from Task<T>.
In addition to the conversions between tasks and observables, Reactive Extensions will also directly support the await keyword. This will return the last item in the IObservable sequence. If one wants all of the items in the sequence then one can convert the IObservable<T> into an IObservable<List<T>> using ToList.
Another change is the replacement of the blocking operations such as Average and ForEach. For example, the new ForEachAsync method will return a Task that can be awaited upon.
Steven Ihde,Karan Parikh Mar 29, 2015