a = new List<int>();
a.Add(0);
for (int i = 0; i < 100; i++)
{
//var t = new Thread(() =>{
// Console.WriteLine(i + " " + Thread.CurrentThread.ManagedThreadId);
//});
//t.Start();
ThreadPool.QueueUserWorkItem((o) =>
{
a[0] = a[0] + 1;
Console.WriteLine(i + " " + Thread.CurrentThread.ManagedThreadId);
});
}
Thread.Sleep(1000);
Console.WriteLine("quit " + a[0]);
结果如下
为什么i一直是100呢?