1
Answer

Having a problem at TimeSpan

Yazan Ersan

Yazan Ersan

10y
2.7k
1
Hi, i created a small download manager.

I've done everything mostly, but having a small problem at timespan. I was calculating left time remaining for the download to be completed. But i'm having a problem at this point :

            double secondsRemaining = ((100 - progressBar.Value) * sw.Elapsed.TotalSeconds / progressBar.Value);
            TimeSpan ts = TimeSpan.FromSeconds(secondsRemaining);

What i get is "TimeSpan overflowed because the duration is too long. I've tried so many formulas, but non of them gives me the exact time left. After i edited the formula a lil bit, i found that the problem is caused by the sign "/" divide.

Thank you.

Answers (1)