Windows 7,Intel CORE i3,64 位,RAM 4Gb,2.27 GHz
.NET Framework 4.0
我有以下代码:
static void Main(string[] args)
{
var timer = new Stopwatch();
timer.Start();
for (int i = 0; i < 0xFFF; ++i)
{
// I use one of the following line at time
Task.Factory.StartNew(() => { });
new Thread(() => { }).Start();
}
timer.Stop();
Console.WriteLine(timer.Elapsed.TotalSeconds);
Console.ReadLine();
}
如果我使用 Task 输出总是小于0.01 秒,但如果我使用 Thread 输出总是大于40 秒!
这怎么可能?为什么差别这么大?