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. same enumeration, different results?

same enumeration, different results?

Scheduled Pinned Locked Moved C#
questioncsharpcomworkspace
25 Posts 4 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.
  • A Alan N

    I'm glad you've come to a solution that you are happy with. One point that I'm not sure you appreciate is that the up time obtained from the performance counter and the TickCount are essentially the same value.

    private void CompareCounterAndTickCount() {
      using (PerformanceCounter ut = new PerformanceCounter("System", "System Up Time")) {
        ut.NextValue();
        TimeSpan counterUpTime = TimeSpan.FromSeconds(ut.NextValue());
        TimeSpan tickCountUpTime = TimeSpan.FromMilliseconds(Environment.TickCount);
        Console.WriteLine("Up Time");
        Console.WriteLine("  from performance counter {0}", counterUpTime);
        Console.WriteLine("  from tickcount           {0}", tickCountUpTime);
      }
    }
    

    On my system the duration reported by TickCount is ~0.2s longer than the performance counter's value which presumably just means the two counters do not share the same origin. Also note the use of the FromMilliseconds method to convert the TickCount to a TimeSpan, much simpler than your multistep calculation! Alan.

    C Offline
    C Offline
    CCodeNewbie
    wrote on last edited by
    #21

    Yes, but I am not trying to get the system start-time. I can already get that using Ravi's post (see my previous question). I explicitly want the System process's start-time.

    A 1 Reply Last reply
    0
    • C CCodeNewbie

      Yes, but I am not trying to get the system start-time. I can already get that using Ravi's post (see my previous question). I explicitly want the System process's start-time.

      A Offline
      A Offline
      Alan N
      wrote on last edited by
      #22

      I can't understand your reasoning in this matter. The SystemUp Time performance counter description is System Up Time is the elapsed time (in seconds) that the computer has been running since it was last started. This counter displays the difference between the start time and the current time. The Environment.TickCount description is A 32-bit signed integer containing the amount of time in milliseconds that has passed since the last time the computer was started. Subtracting either from the current time gets the time when the computer was started. I don't see why (or how) you differentiate the system start time and the "System" process start time. Alan.

      C 1 Reply Last reply
      0
      • C CCodeNewbie

        You need to run it as System (mine impersonates System to get the info, Administrator doesn't have enough privileges) The purpose is a) because it completes the Process listing and allows me to cross-reference against netstat & system boot-time.

        P Online
        P Online
        PIEBALDconsult
        wrote on last edited by
        #23

        CCodeNewbie wrote:

        because it completes the Process listing

        Then just display what the StartTime property tells you and leave it at that.

        C 1 Reply Last reply
        0
        • A Alan N

          I can't understand your reasoning in this matter. The SystemUp Time performance counter description is System Up Time is the elapsed time (in seconds) that the computer has been running since it was last started. This counter displays the difference between the start time and the current time. The Environment.TickCount description is A 32-bit signed integer containing the amount of time in milliseconds that has passed since the last time the computer was started. Subtracting either from the current time gets the time when the computer was started. I don't see why (or how) you differentiate the system start time and the "System" process start time. Alan.

          C Offline
          C Offline
          CCodeNewbie
          wrote on last edited by
          #24

          Hi Alan, The reason(s) for wanting the System process start-time never had anything to do with getting the PCs boot-time. It had to do with being able to complete a running-processes table, x-reference against 2 other sql tables that form part of the project and possibly because I saw so many forum postings that said it can't be done :) Thanks for all your help with this & when I have completed phase 2 and/or 3 I will probably post the whole thing as an article and look forward to your comments.

          1 Reply Last reply
          0
          • P PIEBALDconsult

            CCodeNewbie wrote:

            because it completes the Process listing

            Then just display what the StartTime property tells you and leave it at that.

            C Offline
            C Offline
            CCodeNewbie
            wrote on last edited by
            #25

            The StartTime property, once manipulated to reveal a value, tells you 1601/1/1 00:00:00. That wasn't good enough for me. I wanted the actual StartTime but didn't have the syntactical knowledge of how to get it even if I did have rough idea of how it could be retrieved. Thanks to you, Alan, Ravi & Luc, I (and anybody else Googling "get Window's System process starttime" or something similar), instead of hitting dozens of sites saying it can't be done, now have a solution. I would like to think that's what boards like this are for. Thank you once again for your input.

            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