New Posts  All Forums:Forum Nav:

c# Parallel For

post #1 of 3
Thread Starter 
How would I convert the following for loop to a Parallel.For in c# 2010/.NET 4.0?

int Min = 4;
int Max = 37;

for(int i = Min; i <= Max; i+=2)
{
//execute code
}



Thanx
post #2 of 3
you should be able to figure it out pretty simply by swinging over to MSDN

LINK
:metsyS
(13 items)
 
  
CPUMotherboardGraphicsRAM
950/1.275V/24X167 P6X58D P. 6870 CrossFire DDR3/12GB/668 
Hard DrivePowerCase
C300/128GB AX850 PC-P50WB 
  hide details  
Reply
:metsyS
(13 items)
 
  
CPUMotherboardGraphicsRAM
950/1.275V/24X167 P6X58D P. 6870 CrossFire DDR3/12GB/668 
Hard DrivePowerCase
C300/128GB AX850 PC-P50WB 
  hide details  
Reply
post #3 of 3
You need to add a using reference to System.Threading.Tasks.

Then your code would be something like

//Parallel.For doesn't allow changes to the increment value however we can
//pass it a list of numbers to use
var evens = Enumerable.Range(4, 37).Where(i => i % 2 == 0);

Parallel.For(evens, i =>
{
//Code here using the variable i
});

Just a heads up for such a small range the parallel version might be slower (depending on what your doing inside the loop.)

More info here:
http://stackoverflow.com/questions/3...allel-for-loop
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming