Reactive Extensions and Parallel Extensions

Stephen Toub - MSFT

It’s awesome to see the Reactive Extensions to .NET (Rx) live on the DevLabs site.  If you haven’t checked out this exciting project, we urge you to do so.  Not only is it cool and useful technology, but the download includes a back ported (and unsupported) release of Parallel Extensions for the .NET Framework 3.5 in the form of System.Threading.dll.  Rx relies on this, and you can also use it to try out our new parallel programming support for .NET 4 but with your .NET 3.5 projects.

I recently sat down with Wes Dyer from the Rx team to discuss the Reactive Extensions integration with Parallel Extensions.  You can view a video of that discussion at Wes Dyer and Stephen Toub: Rx and Px – Working Together.

While unsupported, the 3.5 back port does contain all of the types and constructs present in the .NET 4 supported release. In fact, using the back ported version is very similar to using the bits in .NET 4, albeit with a few known differences:

  1. In order to use the features with .NET 3.5 applications, you will need to add a reference to the back ported standalone DLL named System.Threading.dll. This additional step is not present with .NET 4, since the parallel technology is baked into core CLR components.
  2. The performance of the parallel types is optimized for and predicated on the .NET 4 Framework. You should not assume that an application using the .NET 3.5 version will exhibit similar performance characteristics to one using the supported .NET 4 version. Parallel Extensions extensively leverages advancements made in the .NET 4 ThreadPool and other performance optimizations present in .NET 4.
  3. Unlike in .NET 4, the OperationCanceledException type does not have a constructor that accepts a CancellationToken, nor does the exception have a CancellationToken property. In order to throw an exception to cooperatively acknowledge cancellation within a Task, you may use the ThrowIfCancellationRequested method present on the CancellationToken type. Refer to MSDN documentation for more details.
  4. To handle exceptions thrown due to cancellation, users should catch the OperationCanceledException. Although the exception thrown is of type OperationCancelledException2, users will not be able to catch this type as it is an internal exception derived from OperationCanceledException (necessary as part of the back port to maintain consistency).
  5. The Parallel Task and Parallel Stack tool windows in Visual Studio 2010 will not highlight tasks from the .NET 3.5 back port.  These features require .NET 4.
  6. The concurrency visualizations in the Visual Studio 2010 profiler will not show parallel region markers for parallel loops in the .NET 3.5 back port.  This is due to the .NET 3.5 version not outputting any of the ETW events output by the .NET 4 release.

Even with these limitations, we hope you enjoy the release!  You can also expect further integration between Rx and Parallel Extensions in future drops on the DevLabs site.


Discussion is closed.

Feedback usabilla icon