简体   繁体   中英

System.Threading.Tasks

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 write 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM