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

  • Thread starter Thread starter Rene Ren
  • Start date Start date
R

Rene Ren

I can using Environment.TickCount 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
 
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;
 
I can using Environment.TickCount 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 ?

A performance counter can give you that information:


using System;
using System.Diagnostics;

namespace Example
{
public class ExampleClass
{
public static void Main()
{
PerformanceCounter pc = new PerformanceCounter("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.FromSeconds((long) pc.NextValue());

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