Click here to Skip to main content
15,887,979 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In the following z contains two list of objects

How i can accomplish this

What I have tried:

C#
z{
list<row>
list<yy>
}
foreach(var y in z)
                           {
                                DataRow oldRow = y.row;
                                oldRow.SetField<string>("AMOUNT", y.yy.Value);
                           }
Posted
Updated 7-Mar-16 0:29am
v3

1 solution

Parallelism can be accomplish in two ways

1. Parallel class
2. PLINQ (Parallel LINQ)

Here is the code using Parallel class:
C#
string[] lines = File.ReadAllLines("filePath");
List<string> listLines = new List<string>(lines);
Parallel.ForEach(listLines, line =>
{
    //Your stuff
	callMethod(line);
});
</string></string>

Don't choose blindly to choose Parallel class to loop over a list otherwise it may throw you performance overhead. Use Parallel class when you have following requirement:

Execution takes place in parallel way.
Parallel.ForEach uses multiple Threads.
Parallel.ForEach is defined in .Net 4.0 and above frameworks.
Execution is faster.

Note: In your if you are not performing any action then there is no need to use Parallel class. If you see my example it is calling the method inside the loop so it suits the requirement.
 
Share this answer
 
v2
Comments
John C Rayan 7-Mar-16 6:33am    
Indeed. As Manas has mentioned , you have to take extra care when you use Parallel computing. Do not use it if you are not sure what you want.

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