'IndexOutOfRangeException exception when using tasks in for loop in C#

I am trying to use tasks in a for loop, but I am getting really strange exception! here is my code:

        Task[] tasks = new Task[strarrFileList.Length];
        for (int ii = 0; ii < strarrFileList.Length; ii++)
        {
            tasks[ii] = Task.Factory.StartNew(() => mResizeImage2(ii, strarrFileList[ii], intLongSide, jgpEncoder, myEncoderParameters));
        }
        Task.WaitAll(tasks);

Here is the error:

An exception of type 'System.IndexOutOfRangeException' occurred in mCPanel.exe but was not handled in user code Additional information: Index was outside the bounds of the array.

So basically ii becomes equal to strarrFileList.Length which shouldn't! Does anyone have an explanation/solution for this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source