In windows service, how to get the service start time and service end time?
In wind开发者_JAVA技巧ows service, how to get the service start time and service end time?
You could use the System.Diagnostics.Process
class. In particular, the StartTime and ExitTime properties.
//System.Diagnostics.Process p = System.Diagnostics.Process.GetCurrentProcess();
System.Diagnostics.Process p = System.Diagnostics.Process.GetProcessById(6684);
Console.WriteLine(p.StartTime);
//...
Console.WriteLine(p.ExitTime);
Note that you can only call for ExitTime on a process that has completed, and you need to get the handle to the process before it exits.
msdn docs for Process class
I think you would need to do this manually within the OnStart and OnStop/OnShutdown events.
You could also try and interrogate the windows log for some kind of history?
精彩评论