计划计时器每月执行一次 - C# [英] Schedule timer to be executed once a month - C#

查看:87
本文介绍了计划计时器每月执行一次 - C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要每月一次将一些数据从 SQL Server 传输到 MySQL.我已经完成了这个转移的东西,但我不知道(我还没有在互联网上找到)如何设置一个计时器来每个月在特定的一天执行这个转移.我不想仅仅设置一个以毫秒为单位的计时器间隔,因为每个月的天数都不同.

I need to transfer some data from SQL Server to MySQL, once a month. I have already done this transfer stuff, but I don't know (and I have not found out on the internet) how to set a timer that executes this transfer a specific day every month. I don't want just to set a timer interval in milliseconds because the number of days vary from one month to another.

感谢任何帮助...

推荐答案

您可以将 Windows 任务计划程序用于此类工作.在此处查看命令行选项Schtasks(有很多)

You could use the Windows Task Scheduler for this kind of work. Look here for command line options of Schtasks (there's tons of them)

示例 1:

安排在每个月的第一天运行的任务

To schedule a task that runs on the first day of every month

以下命令调度 MyApp 程序在第一个运行每个月的一天.因为值 1 是两者的默认值/mo(修饰符)参数和/d(天)参数,这些参数命令中省略了.

The following command schedules the MyApp program to run on the first day of every month. Because a value of 1 is the default for both the /mo (modifier) parameter and the /d (day) parameter, these parameters are omitted from the command.

schtasks /create /tn "My App" /tr myapp.exe /sc monthly

示例 2:

安排第 15 天的任务

To schedule a task for the 15th day

以下命令安排 MyApp 程序在 15 日运行每月下午 3:00(15:00).它使用/d 参数来指定日期.它还使用/st 参数来指定开始时间.

The following command schedules the MyApp program to run on 15th of every month at 3:00 P.M. (15:00). It uses the /d parameter to specify the date. It also uses the /st parameter to specify the start time.

schtasks /create /tn "My App" /tr myapp.exe /sc monthly /d 15 /st 15:00

这篇关于计划计时器每月执行一次 - C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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