This is caused by i
being declared outside of the for loop, for the entire for loop. Since there is no guarantee that the Thread
is executed at that point, the value of i
can change before the Thread
executes. You can "resolve" this by declaring a local variable in the for loop.
//for loop ..
var localIndex = i;
var temp = new Thread(() => PrintOut(args[localIndex], IsFilePath(args[localIndex])));
temp.Start();
//for loop ..
EDIT: Also, can you please post a code snippet next time, saves me having to write out the code again :P