Thread[] t = new Thread[threadCount];
int m = 0;
foreach (var thread in t)
{
if (m<threadCount)
{
//This one is needed for paintSingleThread as hight of Bitmap
int height = parts[m].Height;
//this line causes the exception
t[m] = new Thread(() => paintSingleThread(parts[m], "Green", height, width));
t[m].Start();
m++;
}
}
parts[] is a BitMap array already filled with bitmap objects. I want to give different members of array for different threads, but sometimes I get IndexOutOfRangeException because m gets too big.It doesn't occur everytime, it's like every other time i run the program. When debugging, every time was smooth and erro never occured. Even with if(m
I'm interested in both the causation of the problem and code changes to avoid this problem.