I'm new to multithreading and i'm having unexpected results with a very simple code:
public void Run()
{
for (int i = 0; i < 10; i++)
{
Thread t = new Thread(() => myFun((i + 1)));
t.Start();
}
}
private void myFun(int threadNo)
{
Console.WriteLine("Thread #" + threadNo.ToString());
}
Can someone explain me why the code above prints this to the console window ?
Thread #3
Thread #3
Thread #3
Thread #6
Thread #6
Thread #8
Thread #9
Thread #10
Thread #11
Thread #11