在特定的日期和时间,每星期C#运行System.Timers.Timer的事件每星期、日期、事件、时间

2023-09-06 16:04:39 作者:满身情歌味

我在写使用System.Timers.Timer的跟踪我的时间的窗口服务的过程。我想要做的是做起来很基础上,我的app.config文件变量我的服务将在一个特定的日期和时间启动。

I'm in the process of writing a windows service using System.Timers.Timer to keep track of my interval. What I'd like to do is make it so my service will launch on a specific day and time based on variables in my app.config file.

推荐答案

虽然我认为最好的办法是让这个计划的任务,你可以轻松地创建一个可等待计时器,将在每天同一时间发出信号。 Windows有一个可等待计时器对象,但有它没有任何.NET支持。

Although I think your best bet is to make this a scheduled task, you can easily create a waitable timer that will signal at the same time every day. Windows has a Waitable Timer object, but there's no .NET support for it.

我发表了一篇文章而回:可等待在C#中,定时器中,我展示了如何使用这个对象从C#程序。全部code可在 http://www.mischel.com/pubs/waitabletimer.zip 。你可以自由地使用它,你认为合适的方式。

I published an article a while back: Waitable Timers in C#, in which I show how to use this object from a C# program. Full code is available at http://www.mischel.com/pubs/waitabletimer.zip. You're free to use it any way you see fit.

 
精彩推荐
图片推荐