I am trying to write some code based on the answer provided in this question. The thing is that in my case I have my own custom data type and I am not using an integer.
How can I do a Parallel.For with a custom data?
This is the answer provided in the linked question
Parallel.For<int>(0, 1000, () => 0, (res, loop, subtotal) =>
{
subtotal += 1;
return subtotal;
},
(x) => Interlocked.Add(ref sum, x)
);
And this is how I am doing my loop without using Parallel.
int value1 = 0;
int value2 = 0;
List<MyData> myDataTypeList = ...
foreach (var myDataType in myDataTypeList)
{
value1 = value1 + Function1(myDataType);
value2 = value2 + Function2(myDataType);
}
Is there a way I can transform my non-parallel loop into a Parallel.For similar to the response provided in the other question?