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();
}
Run Code Online (Sandbox Code Playgroud)
如果我使用Task,输出总是小于0.01秒,但如果我使用Thread,输出总是大于40秒!
这怎么可能?为什么这么大的差异?