Can I use the task parallel library in a .Net 3.5 project?

25,979

Solution 1

(Legacy answer - it seems the backport for 3.5 is no longer readily available.)

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.

Solution 2

As Jon Skeet mentioned, Rx backported TPL to .NET 3.5.

I have made a nuget (called TaskParallelLibrary) out of their System.Threading.dll, for easier integration.

You can get it from http://nuget.org/packages/TaskParallelLibrary.

Share:
25,979

Related videos on Youtube

Mathias
Author by

Mathias

I was a quantitative models guy, but California turned me into a software developer. I primarily write code in F#, with origins in C#, and, even further back, VBA for Excel.

Updated on September 15, 2020

Comments

  • Mathias
    Mathias over 3 years

    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.

  • zneak
    zneak almost 14 years
    If installing something else is a requirement, I think I'd install the .NET Framework 4 altogether.
  • Jon Skeet
    Jon Skeet almost 14 years
    @zneak: In some situations you may have the option of deploying another library, but not upgrading the framework version.
  • Mathias
    Mathias almost 14 years
    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.
  • user423430
    user423430 over 12 years
    Most recent version with System.Threading.dll: stackoverflow.com/questions/6891787/…
  • Omer Mor
    Omer Mor almost 10 years
    It's Microsoft's module. I just repackaged it in nuget form. I don't have the source.
  • Vilius Surblys
    Vilius Surblys over 7 years
    The version that targets 3.5 doesn't appear to be available any more.
  • Jon Skeet
    Jon Skeet over 7 years
    @RowlandShaw: Thanks, have edited the answer. I suspect there are ways of finding it, but most people would be better off spending their time moving off 3.5 :)