Help,How to get the total time elapsed since the system started(more than 1 month)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rene Ren

    #1

    Help,How to get the total time elapsed since the system started(more than 1 month)

    I can using Environment.Tic kCount property to get the time elapsed since the
    system started. but this property using A 32-bit signed integer type, so
    it's can't count the time more than 24.9 days.
    How can I do ?

    tks


  • Morten Wennevik

    #2
    Re: Help,How to get the total time elapsed since the system started(more than 1 month)

    Hi Rene,

    I dont' think it is possible. The TickCount is taken from the system clock, so if the system is up and running for 25+ days this counter is reset.

    If you are measuring how long your application have been running, try stamping the startup and measure the TimeSpan to DateTime.Now;


    On Sat, 01 Oct 2005 09:32:58 +0200, Rene Ren <rene@vip.139sc .com> wrote:
    [color=blue]
    > I can using Environment.Tic kCount property to get the time elapsed since the
    > system started. but this property using A 32-bit signed integer type, so
    > it's can't count the time more than 24.9 days.
    > How can I do ?
    >
    > tks
    >
    >
    >[/color]



    --
    Happy coding!
    Morten Wennevik [C# MVP]

    Comment

    • Chris R. Timmons

      #3
      Re: Help,How to get the total time elapsed since the system started(more than 1 month)

      "Rene Ren" <rene@vip.139sc .com> wrote in
      news:#KszzrlxFH A.3772@TK2MSFTN GP11.phx.gbl:
      [color=blue]
      > I can using Environment.Tic kCount property to get the time
      > elapsed since the system started. but this property using A
      > 32-bit signed integer type, so it's can't count the time more
      > than 24.9 days. How can I do ?[/color]

      A performance counter can give you that information:


      using System;
      using System.Diagnost ics;

      namespace Example
      {
      public class ExampleClass
      {
      public static void Main()
      {
      PerformanceCoun ter pc = new PerformanceCoun ter("System", "System Up Time");
      // The first call to NextValue() returns 0.0.
      pc.NextValue();

      // The second call to NextValue() returns the number of
      // seconds that have elapsed since the machine was turned on.
      TimeSpan ts = TimeSpan.FromSe conds((long) pc.NextValue()) ;

      Console.WriteLi ne("System Up Time: {0} days, {1} hours, {2} minutes, {3} seconds", ts.Days, ts.Hours, ts.Minutes, ts.Seconds);
      }
      }
      }


      --
      Hope this helps.

      Chris.
      -------------
      C.R. Timmons Consulting, Inc.

      Comment

      Working...