Scheduled console app vs Windows service? When is it appropriate to use each

前端 未结 7 2087
误落风尘
误落风尘 2020-12-24 12:55

I just read this: What is the benefit of developing the application as a windows service? but I\'m still unsure of when to use a windows service.

I have a couple tas

7条回答
  •  被撕碎了的回忆
    2020-12-24 13:15

    For single or narrow purpose applications run on a schedule, running a console application via the Task Scheduler is almost always the correct design.

    For long running or complex tasks that may need interaction such as manual start, stop, pausing, continuing, etc. then, in general, a Windows Service is the better option.

    Scheduled tasks can be run under any account and do not need a user logged in just like Services. For single purpose tasks such as those you propose external control of the task is usually irrelevant so you have no need of the controllability of a Service.

    A big factor also is the Task Scheduler is a very robust and flexible event based scheduler. It is extremely unlikely that you could write a scheduler that was more robust and could handle the vagaries of time and trigger based scheduling. In fact there are a number of questions about using timers for scheduling tasks in services on this site and it is remarkable the number of answers (including some of the 'correct' answers) that are poor quality or outright incorrect.

    EDIT: It's also interesting to note that Microsoft policy is shifting away from using services for task based actions. If you check Vista, Win2K8 and Win7 you will notice a growing list of special purpose scheduled tasks that perform system maintenance and many system services.

提交回复
热议问题