I am wanting to use a Parallel For Loop in C# to run a function and write the results to a variable.
This is the current for loop I am using:
string[][,] PatternTables;
for (i = 0; i < BOMs.Length; i++)
{
PatternTables[i] = BOMAnalysis(Pattern, PatternMatch, BOMs, HeaderIndex);
}
also if there is a way to make it so the treads
pause before writing the variable until the previous thread completes would be nice as well to keep things ordered but is no necessary.
Yes I am running the same thing multiple times right now because I have not done a parallel loop before and I want to ensure consistency before adding variation. How do I rewrite this for loop as a parallel for loop so I can get a consistent result?
This is the statement where I seem to be getting most of my errors in:
if (scrMatch)
{
Array.Resize(ref PatternMatch[k][0], PatternMatch[k][0].Length + 1);
Array.Resize(ref PatternMatch[k][1], PatternMatch[k][1].Length + 1);
Array.Resize(ref PatternMatch[k][2], PatternMatch[k][2].Length + 1);
Array.Resize(ref PatternMatch[k][3], PatternMatch[k][3].Length + 1);
Array.Resize(ref PatternMatch[k][4], PatternMatch[k][4].Length + 1);
Array.Resize(ref PatternMatch[k][5], PatternMatch[k][5].Length + 1);
Array.Resize(ref PatternMatch[k][6], PatternMatch[k][6].Length + 1);
int Row = j + 1;
PatternMatch[k][0][PatternMatch[k][0].Length - 1] = Row.ToString();
PatternMatch[k][1][PatternMatch[k][1].Length - 1] = BOMs[i][j, HeaderIndex[4, i]];
PatternMatch[k][2][PatternMatch[k][2].Length - 1] = BOMs[i][j, HeaderIndex[2, i]];
PatternMatch[k][3][PatternMatch[k][3].Length - 1] = BOMs[i][j, HeaderIndex[6, i]];
PatternMatch[k][4][PatternMatch[k][4].Length - 1] = BOMs[i][j, HeaderIndex[3, i]];
PatternMatch[k][5][PatternMatch[k][5].Length - 1] = BOMs[i][j, HeaderIndex[0, i]];
PatternMatch[k][6][PatternMatch[k][6].Length - 1] = BOMs[i][j, HeaderIndex[1, i]];
}