From 51a762992e45fb3d36d969b084208a2f3ffb59c9 Mon Sep 17 00:00:00 2001 From: JeffDChapman Date: Fri, 11 Nov 2016 07:35:23 -0800 Subject: [PATCH] Timer Countdown Only recompute "time remaining" when progress bar changes, otherwise just decrement --- JeffSplit/FileSplitter.cs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/JeffSplit/FileSplitter.cs b/JeffSplit/FileSplitter.cs index 1196be4..8308fe6 100644 --- a/JeffSplit/FileSplitter.cs +++ b/JeffSplit/FileSplitter.cs @@ -21,6 +21,8 @@ public partial class FileSplitter : Form private long baseLineStart = 0; private int secsElapsed = 0; private TimeSpan timeElapsed; + private double lastpctDone = 0; + private TimeSpan lasttimeLeft; public FileSplitter() { @@ -131,8 +133,22 @@ private void tmrSeconds_Tick(object sender, EventArgs e) try { double pctDone = this.pbarSplitPct.Value / 99.9; - TimeSpan timeLeft = TimeSpan.FromSeconds(timeElapsed.TotalSeconds * (1 - pctDone) / (pctDone - baseLineStart)); - this.lblRemaining.Text = String.Format("{0:hh.mm.ss}", timeLeft.ToString()); + if (lastpctDone == pctDone) + { + lasttimeLeft -= TimeSpan.FromSeconds(1); + if (lasttimeLeft < TimeSpan.FromSeconds(0)) + { lasttimeLeft = TimeSpan.FromSeconds(0); } + this.lblRemaining.Text = String.Format("{0:hh.mm.ss}", lasttimeLeft.ToString()); + } + else + { + lastpctDone = pctDone; + TimeSpan timeLeft = TimeSpan.FromSeconds(timeElapsed.TotalSeconds * (1 - pctDone) / (pctDone - baseLineStart)); + if (timeLeft < TimeSpan.FromSeconds(0)) + { timeLeft = TimeSpan.FromSeconds(0); } + lasttimeLeft = timeLeft; + this.lblRemaining.Text = String.Format("{0:hh.mm.ss}", timeLeft.ToString()); + } } catch { }