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

前端 未结 7 2088
误落风尘
误落风尘 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:17

    I would recommend a scheduled task in all cases except programs that need to run at very short intervals, or that run continuously. Programs that start, perform their function, and shutdown have well defined resource lifetimes, perform the appropriate setup and cleanup in a bounded number of steps (and if not, the fact that they don't terminate in the expected time is indication of a bug), and thus are easier to reason about. And you don't need to fiddle about with timers and such.

    Scheduled tasks have equivalent operations to the stop and restart commands of services, ie. disable task, enable task. Simple, and it lets any current operations in progress complete instead of trying to abort them, which is inherently correct way to handle this. Doing all of this state/transition management resource lifetimes manually is just error-prone in the presence of refactoring.

提交回复
热议问题