I have a set of elements (SortedPoints) that I repeat using Parallel.ForEach. Each item will become a key in a dictionary named Stripes. Calculating the value for each item is expensive and is in the BulidStripes method.
Parallel.ForEach(SortedPoints, point =>
Stripes[point] = BuildStripes(point, pointToPosition)
);
I can make Stripes ConcurrentDictionary, but I was wondering if this would work:
1) Make Stripes a regular Dictionary.
2) Periodically sort through all the points and fill in the strips with the display on an empty object.
3) Iterate over all points in parallel and replace the display in Stripes with the actual value returned by BuildStripes.
foreach(var point in SortedPoints)
Stripes[point] = emptyStripe;
Parallel.ForEach(SortedPoints, point =>
Stripes[point] = BuildStripes(point, pointToPosition)
);
, , , ? , , - , .
.