这是我的估计时间代码。它正在工作,但时间有误。
if ((DateTime.Now - _startDate).Seconds > 0)
{
kbPerSecond = (int)((100 * 1000) / 8);
}
long sent = (TotalBytes - BytesRead);
long remainingseconds = sent / kbPerSecond;
string remainingTimeDisplay = string.Empty;
if (remainingseconds > 0)
{
if (remainingseconds > 60)
{
if (remainingseconds > 3600)
{
remainingTimeDisplay += ((int)(remainingseconds) / 3600).ToString("n0") + " Hours, ";
remainingseconds %= 3600;
}
remainingTimeDisplay += (((int)remainingseconds) / 60).ToString("n0") + " Minutes, ";
remainingseconds %= 60;
}
remainingTimeDisplay += ((int)remainingseconds).ToString("n0") + " Seconds remaining";
lbl_estimate.Text = remainingTimeDisplay;
}
问题在于下载完成后,估计的时间会显示为“剩余1秒”而不是零。
我究竟做错了什么?