服务程序每天在特定时间运行 [英] Service program to run at particular time daily

查看:75
本文介绍了服务程序每天在特定时间运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在用c#设计一个Windows服务。我想每天上午11点运行我的功能,即MethodToExecute()。我无法找到在特定时间每天触发我的功能的确切解决方案。请在Windows服务中为我提供触发日常功能的解决方案c#

当我创建一个siolution时,会生成两个事件



Hi ,
I am designing a windows service in c# . I want to run my function i.e "MethodToExecute()" daily at 11 am . I am unable to find the exact solution to trigger my function daily at particular time. Please provide me an solution to for triggering daily thAT function at particular time in Windows Service c#
When I created a siolution two events are generated

protected override void OnStart(string[] args)
{

}

  protected override void OnStop()
{
}







请提供完美的代码来触发该指示每天上午11点



提前致谢。




Please provide me the perfect code to trigger that finction daily at 11 am

Thanks in advance.

推荐答案

如果你有一个流程要运行在特定时间,通常由计划任务而不是服务完成。



但是,你必须启动一个计时器,触发,比方说,每分钟一次。在计时器的回调中,根据预定时间检查当前时间。如果当前时间大于系统时间,请重新安排第二天的事件并运行您的工作人员代码。
If you've got a process to run at a specific time, that would normally be done by a scheduled task, not a service.

But, you'd have to spinup a timer that triggers, say, once a minute. In the callback for the timer, check the current time against your scheduled time. If the current time is greater than the system time, reschedule the event for the next day and run your worker code.


这篇关于服务程序每天在特定时间运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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