Note that there are some explanatory texts on larger screens.

plurals
  1. PONorms, rules or guidelines for calculating and showing "ETA/ETC" for a process
    text
    copied!<p><em>ETC = "Estimated Time of Completion"</em></p> <p>I'm counting the time it takes to run through a loop and showing the user some numbers that tells him/her how much time, approximately, the full process will take. I feel like this is a common thing that everyone does on occasion and I would like to know if you have any guidelines that you follow.</p> <p>Here's an example I'm using at the moment:</p> <pre><code>int itemsLeft; //This holds the number of items to run through. double timeLeft; TimeSpan TsTimeLeft; list&lt;double&gt; 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&lt;&gt;. if (avrage.Count &gt; 30) avrage.RemoveRange(0, 10); milliseconds = 0; } //this.profiler.Interval = 10; private void profiler_Tick(object sender, EventArgs e) { milliseconds += 0.01; } </code></pre> <p>As I am a programmer at the very start of my career I'm curious to see what you would do in this situation. My main concern is the fact that I calculate and update the UI for every loop, is this bad practice? </p> <p>Are there any do's/don't's when it comes to estimations like this? Are there any preferred ways of doing it, e.g. update every second, update every ten logs, calculate and update UI separately? Also when would an ETA/ETC be a good/bad idea.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload