我可以在 .Net 3.5 项目中使用任务并行库吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2987439/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can I use the task parallel library in a .Net 3.5 project?
提问by Mathias
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.
我听说任务并行库可以在 .Net 3.5 项目中使用。这是正确的,如果是,我该如何使用它?在 .Net 4.0 中,它驻留在 System.Threading 中,但是当我在 Visual Studio 2010 中选择 .Net 3.5 作为目标时,我无法访问 Parallel 和 Parallel 循环等类。
采纳答案by Jon Skeet
(Legacy answer - it seems the backport for 3.5 is no longer readily available.)
(传统答案 - 似乎 3.5 的反向移植不再可用。)
You can't use the fullParallel Extensions, no...
您不能使用完整的Parallel Extensions,不...
... but if you install Reactive Extensionsfor .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.)
...但是如果你安装了 .NET 3.5 的Reactive Extensions,它带有一个 Parallel Extensions 版本,所以你可以使用它。我不知道支持多少 PFX,但我怀疑对大多数人来说已经足够了。(博客文章中有一些详细信息,但那是 2009 年的……我不知道 2010 年是否有任何更改,这些更改可能会或可能不会被反向移植。)
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.
请注意,这也是不受支持的 - 对于业余项目可能没问题,但如果我想在商业上使用 PFX,我会升级到 .NET 4。
回答by Omer Mor
As Jon Skeet mentioned, Rxbackported TPLto .NET 3.5.
正如 Jon Skeet 提到的,Rx反向移植TPL到.NET 3.5.
I have made a nuget (called TaskParallelLibrary) out of their System.Threading.dll, for easier integration.
我已经做了的NuGet(称为TaskParallelLibrary)了他们的System.Threading.dll,更容易整合。
You can get it from http://nuget.org/packages/TaskParallelLibrary.

