ETC = 「完了予定時刻」
ループを実行するのにかかる時間を数え、ユーザーに、プロセス全体にかかるおおよその時間を示すいくつかの数値を示しています。これは誰もがときどき行う一般的なことだと思います。従うべきガイドラインがあれば教えてください。
現時点で使用している例を次に示します。
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;
}
私はキャリアを始めたばかりのプログラマーなので、この状況であなたが何をするのか知りたいです。私の主な懸念は、ループごとに UI を計算して更新するという事実ですが、これは悪い習慣ですか?
このような見積もりに関して、すべきこと/すべきでないことはありますか? 毎秒更新する、10 ログごとに更新する、UI を個別に計算して更新するなど、それを行うための好ましい方法はありますか? また、ETA/ETC が良い/悪い考えになるのはいつですか。