如何安排一个C#Windows服务每天运行的方法? [英] How to schedule a C# Windows Service to run a method daily?

查看:197
本文介绍了如何安排一个C#Windows服务每天运行的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:

我怎么可以安排一个C#Windows服务的日常执行任务?

我在创建一个C#Windows服务,但我也没弄明白,使计时器火,每天的方法在app.config文件中指定特定时间的最佳方式(如每天6:00 AM,执行我的方法)。

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).

你怎么办呢?

感谢

推荐答案

此代码应该做到这一点:

This code should do it:

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

这篇关于如何安排一个C#Windows服务每天运行的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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