且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

计划计时器每月执行一次 - C#

更新时间:2023-02-16 13:09:07

您可以将 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