I am running the following simplified code:
public static void runCode(int num){
Console.WriteLine("Task {0}",num);
for(int j=0;j<10;j++)
Console.Write(num);
}
public static void Main(string[] args){
// some operations here
for(int i=0;i<numIterations;i++){
Console.WriteLine("Current number={0}",i);
Task.Run(()=>runCode(i));
}
// remaining code
}
The result is the following one:
Current number=0
Current number=1
Current number=2
Current number=3
Task 4
4444444444Task 4
4444444444Task 4
4444444444Task 4
4444444444
Why does the shown number is always the same? Maybe for static?