For Programmers: Free Programming Magazines  


Home > Archive > ASP .NET > May 2006 > PerformanceCounter / System Up Time / TimeSpan









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author PerformanceCounter / System Up Time / TimeSpan
Rob Meade

2006-05-31, 8:12 am

Hi all,

I'm having a bit of trouble with the following function....

Private Function GetSystemUpTime() As TimeSpan

' declare variables
Dim Result As TimeSpan
Dim PerformanceCounter As PerformanceCounter

' create new instances of our objects
PerformanceCounter = New PerformanceCounter("System", "System Up Time")

' populate
Result = TimeSpan.FromSeconds(PerformanceCounter.NextValue())

' return result
Return Result

End Function

For some reason I keep getting the value 0 (zero) for days, hours,minutes,
seconds etc - ie, I've tried this on 2 machines now and the result is always
the same. I've tried other counters using a similar method (for available
memory,application restarts etc) and they do come through...

Can anyone shed any light on this for me...

PS: I've had a bit of a look online and I'm aware of the environment.tick
thing but that has a problem over a value of 24 (goes to minus numbers) so
would prefer to use a PerformanceCounter object.

Regards

Rob


Brett Wiltshire

2006-05-31, 8:12 am

The first call always returns zero, apparently... see the page here:
http://www.sitepoint.com/forums/pri...ad.php?t=376778


Regards,
Brett.


Rob Meade wrote:
> Hi all,
>
> I'm having a bit of trouble with the following function....
>
> Private Function GetSystemUpTime() As TimeSpan
>
> ' declare variables
> Dim Result As TimeSpan
> Dim PerformanceCounter As PerformanceCounter
>
> ' create new instances of our objects
> PerformanceCounter = New PerformanceCounter("System", "System Up Time")
>
> ' populate
> Result = TimeSpan.FromSeconds(PerformanceCounter.NextValue())
>
> ' return result
> Return Result
>
> End Function
>
> For some reason I keep getting the value 0 (zero) for days, hours,minutes,
> seconds etc - ie, I've tried this on 2 machines now and the result is always
> the same. I've tried other counters using a similar method (for available
> memory,application restarts etc) and they do come through...
>
> Can anyone shed any light on this for me...
>
> PS: I've had a bit of a look online and I'm aware of the environment.tick
> thing but that has a problem over a value of 24 (goes to minus numbers) so
> would prefer to use a PerformanceCounter object.
>
> Regards
>
> Rob


Rob Meade

2006-05-31, 7:11 pm

"Brett Wiltshire" wrote ...

> The first call always returns zero, apparently... see the page here:
> http://www.sitepoint.com/forums/pri...ad.php?t=376778


Hi Bretty,

Thanks for your reply - you know - in the example I saw that had this code
it actually said about that - I assumed - clearly wrongly - that the
"NextValue()" thing meant - go get the next one because the first one is
always zero...

*sigh*

That's taken up 2 hours of my day searching the net just for a
misunderstanding :o(

Anyway, many thanks for your reply - I've for now just duplicated the line
that gets it and it works fine :o)

Thanks

Rob


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com