I have the following code:
string someVariable;
Parallel.For(0, maxCount, count =>
{
Parallel.For(0, dimension, row =>
{
Parallel.For(0, dimension, col =>
{
someVariable = count + " " + row + " " + col;
DoSomethingIndependent(someVariable);
});
});
});
So my question is: is the string variable which is declared outside the loops is independent from each iteration or does the parallel execution of the loops is interrupting with the iterations between each other? I guess that the variable is used at the same time from to parallel threads because it gives me an "Unhandled exception". What is the best way to do this? Maybe using an array of strings for each parallel iteration?
Thanks in advance!