在 MSDN 在线文章《How to: Wait on One or More Tasks to Complete》中,有一段代码:
// Try three different approaches to the problem. Take the first one
tasks2[0] = Task<double>.Factory.StartNew(() => TrySolution1());
tasks2[1] = Task<double>.Factory.StartNew(() => TrySolution2());
tasks2[2] = Task<double>.Factory.StartNew(() => TrySolution3());
调用 3 种不同的方法,它们的功能完全相同,具有完全相同的主体:
static double TrySolution1()
//static double TrySolution2()
//static double TrySolution3()
{
int i = rand.Next(1000000);
// Simulate work by spinning
Thread.SpinWait(i);
return DateTime.Now.Millisecond;
}
我无法理解这些多重重复的实现说明了什么?
与使用一种方法有什么区别
tasks2[0] = Task<double>.Factory.StartNew(() => TrySolution1());
tasks2[1] = Task<double>.Factory.StartNew(() => TrySolution1());
tasks2[2] = Task<double>.Factory.StartNew(() => TrySolution1());
?