[英]Windows Service - C#
如何每小时运行Windows服务?
或者只是编写一个简单的应用程序,然后使用系统的Task Scheduler Service每小时运行您的应用程序-完全不必编写服务。
Based on the description of your problem (which only superficial) I can't think in anything else other than the use of the normal service template provided by VS to create a service and use a Timer to trigger the method that you are interested in running every hour. 根据问题的描述(仅是表面的),除了使用VS提供的常规服务模板来创建服务并使用Timer触发您感兴趣的运行方法外,我别无选择每隔一小时。
About Timer you can also check it out here 关于计时器,您也可以在这里查看
For some more info about how to create the service, in can have a look in the msnd web site 有关如何创建服务的更多信息,请访问msnd网站。
As a simple rule of thumb, never forget to disable the timer just before you starting processing your staff and enable it again at the end 作为简单的经验法则,永远不要忘记在开始处理员工之前禁用计时器,并在最后重新启用它
well you can create a service which works at a time interval of 60 minutes 您可以创建一个以60分钟为间隔运行的服务
timer1 = new Timer();
this.timer1.Interval = 1000 * 60* 60;
this.timer1.Elapsed += new ElapsedEventHandler(timer1_Elapsed);
timer1.Enabled = true;
write this code in the onstart method of the windows service and you will be able to run the service in hourly manner. 在Windows服务的onstart方法中编写此代码,您将能够按小时运行该服务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.