Windows服务OnShutDown()事件未触发 [英] Windows Services OnShutDown() event is not firing

查看:376
本文介绍了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

< a href =http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.aspx> http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog .aspx [ ^ ]。



这是确定是否调用某些内容的最终正确方法。



-SA


这篇关于Windows服务OnShutDown()事件未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆