Alex Rivera | Logout

Retrieve system uptime using C#

Asked 2009-06-09T19:42:01.297
66

Is there a simple way to get a system's uptime using C#?

Edit
Report

1 Answer

0

I know question is both old and solved, but the esiest solution I can tink of is just using the Enviroment.TickCount property, which returns the number of millisecounds since the system started:

System.DateTime SystemStartTime = DateAndTime.Now.AddMilliseconds(-Environment.TickCount);
System.DateTime Uptime = DateAndTime.Now - SystemStartTime;

This solition is a lot faster than the accepted answare.

answered 2013-07-31T19:32:56.927

Your Answer