Windows Service or Task Scheduler for maintenance tasks?

前端 未结 6 1537
一生所求
一生所求 2020-12-31 22:41

I have a C# Application that does some maintenance tasks. It needs to run roughly every hour, although it\'s not too important if it\'s a bit off. And it has to run on a Win

6条回答
  •  天涯浪人
    2020-12-31 23:13

    If you go the services route then I would recommend using System.Threading.Timer. With that you can set it to fire an event once an hour. You can put the interval in the app.config if you think you will ever need to change it.

    Services also run under the local system account (by default) whereas you must supply a username/password when using scheduled tasks. If you use your username it becomes a maintenance issue if you ever change your password and forget to update the task.

    I have a situation where I use a combination of both actually. The service runs constantly during the day but they do network and database maintenance every night. So, I use two scheduled tasks. One to shut the service down at midnight and one to turn it back on at 4am. This is done by calling .BAT files with NET STOP/ NET START commands.

提交回复
热议问题