1
Reply

Having a problem at TimeSpan

Yazan Ersan

Yazan Ersan

Jan 29 2014 2:19 PM
2.7k
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)