I am not really comfortable with multi threaded programming and while I was trying to implement it in my code, was running into an exception which I am not able to figure out why. Any help in this would be greatly appreciated :)
So, basically I have this small snippet of code:
string[][] Array1 = new string[thread_count][];
/* Logic to insert data in Array1 */
Thread[] WorkerThreads = new Thread[thread_count];
for (int i = 0; i < thread_count; i++)
{
/* THE EXCEPTION OCCURS IN THE FOLLOWING LINE */
WorkerThreads[i] = new Thread(() => GetVal(Array1[i], val, num));
WorkerThreads[i].Start();
}
for (int i = 0; i < WorkerThreads.Length; i++)
WorkerThreads[i].Join();
Now, the value for thread_count is set to 10 and I am getting an IndexOutOfRange exception. The debugger shows the value of i as 10 and Array1[10][] is the one it is trying to access.
I am not getting how the value of i can reach 10 when the loop is not supposed to run that far.
Can anyone point out where am I going wrong? I am using C#.
Thanks