It might sound strange, but one feature I really like in an application is the ability to estimate remaining time. Wheter it is the time it will take to install an application, copy a file or perform another lengthy process.
The last time I came across such an application was while installing TrueCrypt. It has a fantastic timer which updates itself continously during the installation.
Here is a method I wrote for Cosmos for determining how much time remains for compiling the operating system. The method takes two arguments, one for how far we've come in the process, and one for the total length of the process.
The major strength of this method is that it continously recalculates how much time remains. So no more "1 second remaining" for minutes, or grossely missing the target by estimating years to copy a single file.
public static System.Diagnostics.Stopwatch xBuildTimer;
public TimeSpan CalculateRemainingTime(int completedCount, int totalCount)
{
if (xBuildTimer == null)
{
xBuildTimer = new System.Diagnostics.Stopwatch();
xBuildTimer.Start();
}
long percentComplete = (completedCount * 100 / totalCount);
if (percentComplete == 0) //Avoid Divide by Zero
percentComplete = 1;
long remaining = (xBuildTimer.ElapsedMilliseconds / percentComplete)
* (100 - percentComplete);
return new TimeSpan(remaining * 10000);
}
No comments:
Post a Comment