views:

538

answers:

2

I heard that the Task Parallel Library can be used in a .Net 3.5 project. Is this correct, and if yes, how do I use it? In .Net 4.0, it resides in System.Threading, but when I select .Net 3.5 as the target in Visual Studio 2010, I don't get access to classes like Parallel and the Parallel loops.

A: 

Simply put: you can't. In doubt, check the MSDN page (which clearly states this is available from the .NET Framework 4).

Features accessible from C# can actually have (at least) three origins: CLR features, .NET Framework features, and compiler features. There's a distinction to do here. Compiler features (like the var keyword) can be used with older .NET Framework targets because they're independant of it. However, features that rely on the runtime (like the dynamic) require a certain version of the CLR to work. The same goes for the framework: if you see something new in the framework, then it surely requires at least this version of the framework.

zneak
I'm using Task Parallel Library June'08 CTP in my 3.5 application.
Vasiliy Borovyak
+5  A: 

You can't use the full Parallel Extensions, no...

... but if you install Reactive Extensions for .NET 3.5, that comes with a version of Parallel Extensions, so you can use that. I don't know how much of PFX is supported, but I suspect there's enough for most people. (There are some details in the blog post, but that was from 2009... I don't know about any changes in 2010 which may or may not have been backported.)

Note that this is unsupported, too - probably fine for hobby projects, but if I wanted to use PFX commercially, I'd upgrade to .NET 4.

Jon Skeet
If installing something else is a requirement, I think I'd install the .NET Framework 4 altogether.
zneak
@zneak: In some situations you may have the option of deploying another library, but not upgrading the framework version.
Jon Skeet
Works a charm, thank you! @zneak: I have .Net 4.0 installed, the problem is that I need to work with a component which can talk to .Net dlls, but up to .Net 3.5 only.
Mathias