开发者

In windows service, how to get the service start time and service end time?

开发者 https://www.devze.com 2023-02-16 23:38 出处:网络
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.

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消