Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the DateTime when the current process started?

How to get the DateTime when the current process started?

like image 858
Jader Dias Avatar asked Jan 07 '10 15:01

Jader Dias


2 Answers

The StartTime property on the Process type is returning that value:

Process.GetCurrentProcess().StartTime

This can of course be used to pick up the start time of other processes as well:

Process p = Process.GetProcessesByName("Notepad").FirstOrDefault();
if (p != null)
{
    Console.WriteLine(p.StartTime);
}
like image 166
Fredrik Mörk Avatar answered Oct 21 '22 09:10

Fredrik Mörk


You will need the Process Class found in System.Diagnostics.

using System.Diagnostics;

then a function like this will suffice.

public DateTime GetStartTime()
{
    return Process.GetCurrentProcess().StartTime;
}
like image 42
Skintkingle Avatar answered Oct 21 '22 11:10

Skintkingle