Schedule timer to be executed once a month - C#

让人想犯罪 __ 提交于 2019-12-02 10:42:36

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)

Example 1:

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

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

Example 2:

To schedule a task for the 15th day

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

This sounds like something you should set-up as a scheduled task or a SQL server job rather than having a process run for a month via a timer?

Links:

I guess you could also setup a task as a windows service and check the last time you did the update via a setting in the database, but that seems like overkill. From the sound of it you already have a C# app setup that does the job, so I would just make a scheduled windows task.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!