Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Service or Scheduled Task, which one do we prefer?

If we need to write a program that works periodically, which way do we prefer? Writing a windows service or writing a console application which works as scheduled task?

like image 985
NetSide Avatar asked Apr 20 '09 09:04

NetSide


People also ask

What is the difference between Windows service and Task Scheduler?

A Windows service in meant to run an application 24/7 and it has many recovery options. Task Scheduler is meant to run an application periodically and not 24/7; therefore there isn't any recovery option.

Is there something better than Task Scheduler?

Task Scheduler alternatives can include freeware schedulers, enterprise solutions and workflow automation tools. Our list of top Task Scheduler alternatives includes workload automation tools, enterprise job schedulers, lightweight schedulers and more.

When should you use Windows services?

You would typically want to use Windows services when you need to build and implement long-running jobs that would be executed at predefined intervals of time. Your Windows service would continue to run in the background while the applications in your system can execute at the same time.

Is a scheduled task a service?

Services are for running "constant" operations all the time. Scheduled Tasks are for running single units of work at scheduled intervals (what you want). Really, Scheduled Tasks itself is a service already.


Video Answer


2 Answers

I would suggest running the process as a scheduled task if you can, and writing a service only if you need to. Services are quite a bit more difficult to write (correctly), and if you're running your process on a schedule of any sort, you're much better off using the windows scheduler than attempting to build a scheduler of your own (within the servce).

  • The windows task scheduler is more efficient than your home-made scheduler will be
  • The windows task scheduler offers a number of options that you almost certainly won't attempt to replicate, but may find useful later on
  • If you build a service, you'd have to recompile the program if you want to change the logic that determines what conditions to run the task under. If you use the scheduler, you just flip some options and are done with it.

If you're trying to decide between the two, then obviously using the Task Scheduler is a viable option. And if using the Task Scheduler is a viable option, then building a service is almost certainly the wrong choice.

like image 189
tylerl Avatar answered Oct 21 '22 01:10

tylerl


Depends on just how regular you need it to run.

If its something that needs to run every 60 seconds all day, I'd go with a Windows Service.

If its something that only needs to run once a day, I'd go with Scheduled Task

Anything in the middle... use your judgement :)

like image 32
Eoin Campbell Avatar answered Oct 21 '22 00:10

Eoin Campbell