Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Problem/bug in .net class library

Problem/bug in .net class library

Scheduled Pinned Locked Moved C#
helpcsharpquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mikael Edlund
    wrote on last edited by
    #1

    I have written some code in C# and I can't understand why it behaves the way it does. It is supposed to retrieve the number of seconds that the computer has been turned on and it looks like this:

    PerformanceCounter thePerfCounter = new PerformanceCounter( "System", "System Up Time" );
    float systemUpTime = thePerfCounter.NextValue( );

    The thing is that it always returns 0.0 and I am pretty sure my computer has been up for longer than that... :-) If I call NextValue() a second time it returns the correct uptime though. Does anyone have any idea why it behaves like this? thanks for the help /Mike

    J 1 Reply Last reply
    0
    • M Mikael Edlund

      I have written some code in C# and I can't understand why it behaves the way it does. It is supposed to retrieve the number of seconds that the computer has been turned on and it looks like this:

      PerformanceCounter thePerfCounter = new PerformanceCounter( "System", "System Up Time" );
      float systemUpTime = thePerfCounter.NextValue( );

      The thing is that it always returns 0.0 and I am pretty sure my computer has been up for longer than that... :-) If I call NextValue() a second time it returns the correct uptime though. Does anyone have any idea why it behaves like this? thanks for the help /Mike

      J Offline
      J Offline
      James T Johnson
      wrote on last edited by
      #2

      From the docs.

      Note If the calculated value of a counter depends on two counter reads, the first read returns 0.0.

      My guess is that the uptime counter requires two reads :) James Sonork ID: 100.11138 - Hasaki "Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. :-D" - Michael P Butler Jan. 18, 2002

      L 1 Reply Last reply
      0
      • J James T Johnson

        From the docs.

        Note If the calculated value of a counter depends on two counter reads, the first read returns 0.0.

        My guess is that the uptime counter requires two reads :) James Sonork ID: 100.11138 - Hasaki "Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. :-D" - Michael P Butler Jan. 18, 2002

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Yes, I have read that note, but it does not make any sense. Why should I have to read a counter twice to get the system up time?? A related question: I am trying to write the same program in managed C++ but the System::Diagnostics namespace does not contain the PerformanceCounter class. Why? Shouldn't the class library be identical beetween the languages? thanks for the help /Mike

        L 1 Reply Last reply
        0
        • L Lost User

          Yes, I have read that note, but it does not make any sense. Why should I have to read a counter twice to get the system up time?? A related question: I am trying to write the same program in managed C++ but the System::Diagnostics namespace does not contain the PerformanceCounter class. Why? Shouldn't the class library be identical beetween the languages? thanks for the help /Mike

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          I found the solution to my managed C++ problem. I had to add a

          #using <System.dll>

          to the program. Stupid newbie mistake... :)

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups