Dirk Reske <_F*******@gmx. net> wrote:
when I do:
TimeSpan ts = TimeSpan.FromTi cks(System.Envi ronment.TickCou nt);
textBox1.Text = ts.Hours.ToStri ng() + ":" + ts.Minutes.ToSt ring() + ":" +
ts.Seconds.ToSt ring();
I get: 0:0:6 my computer is on for more than 15 hours now!!!!!
The problem is in what is meant by "tick" here. From
System.Environm ent.TickCount:
<quote>
Property Value
A 32-bit signed integer containing the amount of time in milliseconds
that has passed since the last time the computer was started.
</quote>
Note the "in milliseconds" bit.
Now from TimeSpan.FromTi cks:
<quote>
Remarks
This is a convenience method with the same behavior as the TimeSpan
constructor.
</quote>
the constructor in question is TimeSpan(long), which has this
information:
<quote>
Parameters
ticks
A time period expressed in 100-nanosecond units.
</quote>
So Environment.Tic kCount is giving it in milliseconds, and you're then
constructing a TimeSpan with that number of 100-nanosecond units.
Instead of that, if you use TimeSpan.FromMi lliseconds() you'll get a
much more appropriate figure.
--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too