public class EtcCalculator { private readonly DateTime _startTime; private readonly int _imax; // upper bound of the zero-based array being processed /// <summary> /// /// </summary> /// <param name="maxIndex">upper bound of the zero-based array being processed</param> public EtcCalculator(int maxIndex) { _imax = maxIndex; _startTime = DateTime.Now; } public DateTime GetEtc(int iterationsDone) { var iterationsTotal = _imax + 1; var msElapsed = DateTime.Now.Subtract(_startTime).TotalMilliseconds; var unitTime = msElapsed / (double)iterationsDone; var etc = DateTime.Now.AddMilliseconds(unitTime * (iterationsTotal - iterationsDone)); return etc; } }
// TODO: Initialize items List var i = 0; var timer = new EtcCalculator(items.Count - 1); foreach (var item in items) { // TODO: Process item i++; Console.WriteLine($"ETC = {timer.GetEtc(i)}"); }
ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.