PerformanceCounter / System Up Time / TimeSpan

Discussion in 'ASP .Net' started by Rob Meade, May 31, 2006.

  1. Rob Meade

    Rob Meade Guest

    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, May 31, 2006
    #1
    1. Advertising

  2. The first call always returns zero, apparently... see the page here:
    http://www.sitepoint.com/forums/printthread.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
     
    Brett Wiltshire, May 31, 2006
    #2
    1. Advertising

  3. Rob Meade

    Rob Meade Guest

    "Brett Wiltshire" wrote ...

    > The first call always returns zero, apparently... see the page here:
    > http://www.sitepoint.com/forums/printthread.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 :eek:(

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

    Thanks

    Rob
     
    Rob Meade, May 31, 2006
    #3
  4. Rob Meade

    Rob Meade Guest

    In addition...

    Anyone know if its possible to pull the same information from different
    machines on the network?

    A new instance of PerformanceCounter seems to be able to take a machine
    name - but I've tried this and get access denied errors...

    I guess i some how need to be able to tell the servers in question that the
    ASP.Net process model is allowed to access this?

    Any ideas anyone?

    My other thought was as a web service, so I have one page which drags the
    info from the other servers, this would of course then rely on IIS being
    present, not so good for my clustered SQL Servers! Open to suggestions...

    Regards

    Rob
     
    Rob Meade, May 31, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VB Programmer

    Question: TimeSpan

    VB Programmer, Jul 14, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    433
    Hans Kesting
    Jul 15, 2004
  2. =?Utf-8?B?S2VubmV0aCBQ?=

    Using TimeSpan or Elapsed e.t.c. Methods

    =?Utf-8?B?S2VubmV0aCBQ?=, Nov 6, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    1,420
    =?Utf-8?B?S2VubmV0aCBQ?=
    Nov 7, 2004
  3. Henning Krause [MVP]
    Replies:
    0
    Views:
    361
    Henning Krause [MVP]
    May 25, 2005
  4. Rosanne

    TimeSpan problem

    Rosanne, Jul 19, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    520
    Eliyahu Goldin
    Jul 20, 2005
  5. Avi

    PerformanceCounter for a specific process

    Avi, Feb 1, 2006, in forum: ASP .Net Web Services
    Replies:
    2
    Views:
    149
Loading...

Share This Page