Windows Scheduled Task vs Windows Service
Points to consider whether to use scheduled task or windows service
From time to time you have a need to implement some maintainance opration for your application server. Whether it is just a simple temporary file deleting pr something more complicated.
Two most common ways to do this are either using
- Windows Scheduled Task
- Windows Service
Both can do most of the work you need, but both also have some advantages and disadvantages and based on your needs you should go with one or another.
The following are things you should take into concern
The frequency of the operation to be executed
If you have to execute some operation not so often, it does not make sense to have piece of memory used most of the time. Let's say you send some emails once a week or daily. This is pretty much a scenario where you should go with scheduled task.
Otherwise, if you are running task very often, scheduled task is not so suitable as process may time more time than schedule pause and at some point
If your scheduled operations needs to provide some data to other process, you should keep it as a service. Let's say you want to send push notifications to mobile devices. You are not sure about the frequency, which might be even one a day or once in few days, but you need to ensure that some other application can invoke this operation any time.
Scheduled task starts and ends, it does not reside in the memory. This scenario should be implemented as a service which resides in memory and can provide certain operation at any time.
The complexity of implementation
Scheduled operation can be pretty much any executable on the Windows system. It can be simple console application, or it can have some UI which informs user that something is going on in a nice fancy dialog window, it can also be DOS batch (*.bat) or command (*.com) file.
Anyhow, you have more options how are you going to perform your operation which gives you certain range of flexibility to do it.
With services you do not have that freedom. Services are not so easy to debug (at least not easy as Windows Forms or console applications).
If you are not so good with code and you do not have some really complex operation, you should go with one of the options for scheduled task
While scheduled task can be only invoked after some time span expires, service have more options to initiate some processing.
For example, if you need to perform some action when some file changes, you would have to use windows service which resides in memory and monitors specific file for a change.
If you have any other things that should be taken in concern regarding this topic please post a comment below
Purpose of the code contained in snippets or available for download in this article is solely for learning and demo purposes. Author will not be held responsible for any failure or damages caused due to any other usage.
Comments for this article