.netc#-4.0parallel-processingtaskparallel-extensions

any special reference needed for c# 4.0 Parallel.For?


I am following this article: Link

and in my console app Parallel namespace is visible, but "Parallel.For" fails compilation with "type of namespace For does not exist in namespace 'Parallel'".

I've scoured the net, but not seeing anything other than it is in System.Threading which is a namespace i've added (although it is not an assembly reference, and i don't see it in .Net framework references list).

using vs2010 project is using framework 4.0.

here are my usings:

using System;
using System.Threading.Tasks;
using System.Threading;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

offending code:

        Parallel.For(2, 20, (i) => {
            var result = SumRootN(i);
            Console.WriteLine("root {0} : {1} ", i, result);
        });

Solution

  •     System.Threading.Tasks
    

    After a closer look at your error message i think that maybe you are using "Parallel" as the name/namespace for your project?

    In case of doubt you can use System.Threading.Tasks.Parallel.For(...)