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);
}
}
}