Essentially, I am working with this:
var data = input.AsParallel();
List<String> output = new List<String>();
Parallel.ForEach<String>(data, line => {
String outputLine = "";
// ** Do something with "line" and store result in "outputLine" **
// Additionally, there are some this.Invoke statements for updating UI
output.Add(outputLine);
});
Input is a List<String>
object. The ForEach()
statement does some processing on each value, updates the UI, and adds the result to the output
List
. Is there anything inherently wrong with this?
Notes:
- Output order is unimportant
Update:
Based on feedback I've gotten, I've added a manual lock
to the output.Add
statement, as well as to the UI updating code.