Windows服务OnShutDown()事件未触发
问题描述:
我想创建一个服务,在OnStart事件中记录操作系统的时间,并在OnShutDown事件中保存该开始时间和结束时间。但onShutDown()事件未触发。在OnStop事件中运行相同的代码。
I want to create a service which note the time of OS in OnStart event and save that start time and end time in OnShutDown event. But onShutDown() event is not firing. Same code is running in OnStop event.
Me.ServiceProcessInstaller1.Account =System.ServiceProcess.ServiceAccount.LocalSystem
Me.ServiceInstaller1.StartType = System.ServiceProcess.ServiceStartMode.Automatic
答
使用System.Diagnostics.EventLog
:
http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog .aspx [ ^ ]。
这是确定是否调用某些内容的最终正确方法。-SA