I\'m trying to understand why this code is not working.
private static object _lock;
public static void Main (string[] args)
{
Thread th
Because each thread is refering to the loop variable, and does not get its own copy at the time you create the thread.
Notice that the compiler is warning you: "Access to a modified closure".
foreach (int num in Enumerable.Range(0,5))
{
int loopnum = num;
thread = new Thread(() => print(loopnum.ToString()));
thread.Start();
}