can anyone please tell me, how is it possible that this code:
for (byte i = 0; i < someArray.Length; i++)
{
pool.QueueTask(() =>
{
if (i > 0 && i < someArray.Length)
{
myFunction(i, someArray[i], ID);
}
});
}
falls on the line where myFunction
is called with IndexOutOfRangeException
because the i
variable gets value equal to someArray.Length
? I really do not understand to that...
Note: pool
is an instance of simple thread pool with 2 threads.
Note2: The type byte
in for loop is intentionally placed because the array length can not go over byte max value (according to preceding logic that creates the array) and I need variable i
to be of type byte
.