How to schedule a C# Windows Service to run a method daily? [duplicate]

爷,独闯天下 提交于 2019-12-01 08:42:12

问题


Possible Duplicate:
How might I schedule a C# Windows Service to perform a task daily?

I am creating a C# Windows Service, but I didn't figure out the best way to make timer fire a method daily at a specific time specified in App.Config file (e.g. daily at 6:00AM, my method is executed).

How do you do it?

Thanks


回答1:


This code should do it:

Trigger tg = new DailyTrigger();
ScheduledTasks st = new ScheduledTasks();
Task t = st.OpenTask("foo");
t.Triggers.Add(tg);
t.Save();



回答2:


Create a scheduled task. It's by far the easiest way. If you've got enough access to install a service you should have enough access to set up a scheduled task.



来源:https://stackoverflow.com/questions/922444/how-to-schedule-a-c-sharp-windows-service-to-run-a-method-daily

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!