我在一个循环中运行,并以下列方式拉开任务:秒表在任务似乎是所有任务的添加剂,要测量的只是任务间隔
var iResult = new List<Task>();
foreach(var i in myCollection)
{
var task = Task.Factory.StartNew(() =>
DoSomething(), TaskCreationOptions.LongRunning);
task.ContinueWith(m => myResponseHandler(m.Result));
iResult.Add(task);
}
在我的DoSomething()
方法,我有一个计时器:
public static myMsg DoSomething()
{
var timer = System.Diagnostics.Stopwatch.StartNew();
DoLongRunningTask(); //If it matters this hits a REST endpoint (https)
timer.Stop();
return new myMsg(timer.ElaspedMilliseconds);
}
当我通过我的myMsg
的的ElaspedMilliseconds的列表迭代似乎是完全添加剂 - 在第一个的ElaspedMilliseconds可能是300,但最后一个可能是50000(50秒), - 这实际上是一个整个事情需要运行的时间(由另一个计时器测量)。
Updated [my answer](http://stackoverflow.com/a/16259019/200449)。它只是看起来似乎是累加性的,因为ElapsedMilliseconds值总是以递增顺序输出 - 按任务完成顺序(按任务持续时间顺序),这不是任务启动的顺序 – 2013-04-28 07:55:02