Click here to Skip to main content
15,901,122 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Hai All,

I am new to C#4.0 I need to convert for loop to parallel.for loop.

C#
for (int i = 0; i < _queues.Length; ++i)
           {
               _queues[i] = new LinkedList<IHasWorkItemPriority>();
           }


please convert this for to parallel.For.
Posted
Updated 24-Nov-11 23:04pm
v2

1 solution

Why? It isn't going to improve performance by a significant amount - all it is doing is allocating a new linked list structure, which will take almost no time. Paralleling this code will likely make it slower, not faster as it will introduce an overhead in the task construction / destruction.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 25-Nov-11 5:00am    
Agree, a 5.
--SA
sacraj 25-Nov-11 5:01am    
please convert this to Parallel.For
sacraj 25-Nov-11 5:01am    
It is very urgent requirement. Not related to performance
OriginalGriff 25-Nov-11 5:05am    
Why? The only reason for using Parallel.For is for performance reasons - if it is going to worsen performance, then it isn't worth doing. Why waste my time, and yours doing something that is going to make things worse, not better?
sacraj 25-Nov-11 5:10am    
Please explain ++i vs i++ in Paraller.For. I am in urgent need

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900