开发者

System.Threading.Tasks

开发者 https://www.devze.com 2023-02-12 05:18 出处:网络
i am trying to use that reference. i know it is in c# 4. i don\'t know what i currently have. but basically, when i w开发者_如何学编程rite the line:

i am trying to use that reference. i know it is in c# 4. i don't know what i currently have.

but basically, when i w开发者_如何学编程rite the line:

Task.Factory.StartNew(someMethod);

it tells me that it is a mistake. is there any way to solve it so my ide will identify that library (Task Parallel Library)?


You just need a using directive of

using System.Threading.Tasks;

You shouldn't need to add any extra references - Task is in mscorlib.

Are you sure you're targeting .NET 4? Check in your project properties. (The types available don't depend on the version of the language you're using, but the version of the framework you're using.)


You can see what framework version you're targeting by right-clicking your project and selecting Properties. On the Application tab, your framework version will be in the "Target framework" dropdown. If there is no Application tab, check for a Silverlight tab.

If you are targeting .NET 4, then Task is already referenced; see Jon's answer.

If you are targeting .NET 3.5, then you can get Task by downloading Microsoft Reactive Extensions and adding those libraries as references.

If you are targeting .NET 2 or Silverlight, then you're out of luck; Task is not available on those systems.


You probably have a reference to an earlier version of mscorlib. Make sure you have the 4.0 version. If you have an earlier one referenced (like 2.x), delete the reference and add the one for 4.0.


Are you sure your code looks something like this

var task2 = Task.Factory.StartNew(() => pr.DoSomething());

Please share your code if the issue still persists.

0

精彩评论

暂无评论...
验证码 换一张
取 消