[Mono-list] Environment.TickCount not as documented by MS (was: A mono bug)?
Paolo Molaro
lupus@ximian.com
Sat, 21 Feb 2004 19:44:25 +0100
On 02/19/04 Iain McCoy wrote:
> On Thu, 2004-02-19 at 02:16, Lawrence Oluyede wrote:
> > I've written a simple script to compute the uptime of the machine.
> > It works well on MS.NET on Win2k (i tried to compare the output with
> > some other similar utilities) but on Mono 0.29 on my Gentoo box it fails
> > (the procps uptime tells me another time instead of the one that i get
> > with my uptime). Maybe I'm wrong or maybe Mono is wrong... anyway I
> > can't install Mono 0.30 cause it doesn't compile on Gentoo and on
> > Windows it doesn't run :(
> >
> It seems that for Environment.TickCount mono returns basically the same
> thing as it returns for DateTime.Ticks.
>
> Environment.TickCount's icall looks like this:
> res = (gint32) gettimeofday (&tv, &tz);
>
> if (res != -1)
> res = (gint32) ((tv.tv_sec & 0xFFFFF) * 1000 +
> (tv.tv_usec / 1000));
> return res;
>
> while the DateTime_GetNow icall does this:
> if (gettimeofday (&tv, NULL) == 0) {
> res = (((gint64)tv.tv_sec + EPOCH_ADJUST)* 1000000 +
> tv.tv_usec)*10;
> return res;
> }
>
>
> These are rather more similar than makes sense, in any case.
>
> Anyway, Environment.TickCount is documented by MS (at
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemEnvironmentClassTickCountTopic.asp) as "containing the amount of time in milliseconds that has passed since the last time the computer was started". I think mono's implementation should probably do something similar, although I'm not yet sure what the correct way to do that something similar would be.
We may change TickCount to return the time since the computer started
in the future, but it's sure not a priority. That said, anyone who uses
Environment.TickCount to get the uptime of a system is writing very
buggy code. Hint:
lupus@luna:~$ w
19:44:02 up 139 days, 2:45, 1 user, load average: 1.29, 1.15, 1.11
lupus
--
-----------------------------------------------------------------
lupus@debian.org debian/rules
lupus@ximian.com Monkeys do it better