views:

441

answers:

4

Is there a way I can determine how long an application pool (in IIS7) has been up (time since started, or last restart) in c#?

+1  A: 

From the ASP.NET application, you can try TimeSpan uptime = (DateTime.Now - ProcessInfo.GetCurrentProcessInfo ().StartTime)

Gonzalo
+1  A: 

Really stupid trick: in some class that everything uses, use a class constructor to remember your start time and use an aspx page to receive it. Now compare to current time.

Joshua
By class constructor do you mean `static` constructor? Because the static constructor is what you'd want to do with this, I've never considered how easily you could use a static constructor to achieve something like this before though.
Chris Marisic
Yeah class constructor in IL = static constructor in C#.
Joshua
A: 

DateTime.Now - Process.GetCurrentProcess().StartTime

Process.GetCurrentProcessInfo() doesn't exist.

Eric Humphrey