Parallelism can be accomplish in two ways
1. Parallel class
2. PLINQ (Parallel LINQ)
Here is the code using Parallel class:
string[] lines = File.ReadAllLines("filePath");
List<string> listLines = new List<string>(lines);
Parallel.ForEach(listLines, line =>
{
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.