在一定的时间每​​天执行一些代码 [英] execute some code at a certain time daily

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

问题描述

我怎么能执行一些代码,每日一次。
例如每天下午三时调用的MyMethod()。
(提供的应用程序正在运行,当然)...

How can I execute some code, once a day. e.g. call MyMethod() at 3pm every day. (provided the app is running of course)...

我试着做这在C#的WinForms。

Im trying to do this in c# winforms.

推荐答案

如果您只是想在每天同一时间运行的东西,你可以使用内置的任务调度<​​/A>。

If you simply want to run something at the same time every day, you can use the built in task scheduler.

您可以设置每日计划,将在每天的同一时间执行应用程序。

You can setup a daily schedule that will execute your application at the same time every day.

否则,在你的应用程序,你需要安装一个的定时器并检查当前的时间是下午3点只是打电话给你在这一点的方法。

Otherwise, in your application you will need to setup a timer and check in the tick event if the current time is 3pm and only call your method at that point.

我会建议一个窗口服务,但正如你说,你只需要运行应用程序是否已经运行,这是没有必要的方法。

I would have suggested a windows service, but as you stated that you only need the method to run if the application is already running, this is not needed.

这篇关于在一定的时间每​​天执行一些代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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