How can I make the code below parallel, without locks
List l = new List();
foreach (var item in sourceCollection)
{
L.Add(Process(item));
}
I prefer answers for c# 3.5, but 4.0 will be also ok
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Here’s an example of taking a sequence of numbers, performing some costly operation on each of them in parallel, and then aggregating the result (not in parallel).
Just be careful about thread safety in the operation you perform in the delegate.