I am trying to run several tasks at the same time and I came across an issue I can\'t seem to be able to understand nor solve.
I used to have a function like this :<
All your lambdas capture the same variable which is your loop variable. However, all your lambdas are executed only after the loop has finished. At that point in time, the loop variable has the maximum value, hence all your lambdas use it.
Stephen Cleary shows in his answer how to fix it.
Eric Lippert wrote a detailled two-part series about this.