如何每天在特定时间(例如:12:00 PM)启动/运行Windows服务? [英] how to start/run a windows service at particular time (say: 12:00 PM) every day?

查看:117
本文介绍了如何每天在特定时间(例如:12:00 PM)启动/运行Windows服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:我开发了一个Windows服务,该服务每天运行一次,并且可以正常工作(一切都很好!)

问题:服务在前一天完全在同一时间运行(上次运行时间).例如:如果我今天下午4:00启动服务,那么它将在每天下午4:00再次运行.

我的解决方案到目前为止(但无法正常工作),我希望它使用app.config文件中提到的 StartTime IntervalTime 对其进行自我配置,并每天在该时间运行(不管我什么时候开始)

在这个愚蠢的事情上有问题..请在这方面提供示例代码.非常感谢您的帮助,在此先感谢.

为了进一步澄清,如果我在app.config中提到过

Background: I have developed a windows service which runs once every day and does the work (every thing is just right!)

Issue: the service runs exactly at the same time (last run time) the other day.. Ex: If I start the service at 4:00 PM today so it will run again at 4:00 PM every day.

My solution till yet (but not working fine) I want it to configure it self with the StartTime and IntervalTime mentioned in the app.config file and run at that time everyday (regardless of when I have started it)

Having problems with this silly thing .. Please help in this regards with sample code. Your help is really appreciated, Thanks in advance.

For further clarification, if I have mentioned in app.config

key="StartTime" value="12:00"
key="Interval" value="86400000"



因此,无论我启动或启用它的时间如何,它都必须每天运行于12:00 PM(间隔时间为86400000毫秒,即1天).



so it must run on 12:00 PM every day (as interval period is 86400000 milliseconds i.e. 1day) regardless of the time when I started it or make it live.

推荐答案


您最好的选择就是编写一个标准程序,并在计划任务"下执行该程序,该程序将处理您的所有问题
A windows service is not really meant to work like this, a service is ''constantly running'' rather than interval based.

Your best bet here is just to write a standard program and have it execute under ''Scheduled Tasks'' which will handle all of your issues


这篇关于如何每天在特定时间(例如:12:00 PM)启动/运行Windows服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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