ETC = "Estimated Completion Time"
I calculate the time taken to complete the cycle and show the user some numbers that tell him how much time the whole process will take. I feel that this is a common thing that everyone does sometimes, and I would like to know if you have any recommendations that you follow.
Here is an example that I am currently using:
int itemsLeft; //This holds the number of items to run through. double timeLeft; TimeSpan TsTimeLeft; list<double> avrage; double milliseconds; //This holds the time each loop takes to complete, reset every loop. //The background worker calls this event once for each item. The total number //of items are in the hundreds for this particular application and every loop takes //roughly one second. private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e) { //An item has been completed! itemsLeft--; avrage.Add(milliseconds); //Get an avgrage time per item and multiply it with items left. timeLeft = avrage.Sum() / avrage.Count * itemsLeft; TsTimeLeft = TimeSpan.FromSeconds(timeLeft); this.Text = String.Format("ETC: {0}:{1:D2}:{2:D2} ({3:N2}s/file)", TsTimeLeft.Hours, TsTimeLeft.Minutes, TsTimeLeft.Seconds, avrage.Sum() / avrage.Count); //Only using the last 20-30 logs in the calculation to prevent an unnecessarily long List<>. if (avrage.Count > 30) avrage.RemoveRange(0, 10); milliseconds = 0; } //this.profiler.Interval = 10; private void profiler_Tick(object sender, EventArgs e) { milliseconds += 0.01; }
As a programmer at the very beginning of my career, I am curious to see what you will do in this situation. My main problem is that I am calculating and updating the user interface for each cycle, is this a bad practice?
Is there anything to do / not do when it comes to such evaluations? Are there any preferred methods for their implementation, for example. update every second, update every ten logs, calculate and update the user interface separately? Also when ETA / ETC would be a good / bad idea.
source share