2

My issue is pretty simple. I have an application that should be executed automatically once a day. I have no prior experience with this kind of scenario (some time ago I worked with IBM Control-M but guess that it is way more complete, complex and expensive =))

I thought about two possible solutions:

  • Creating a Task inside Windows Task Scheduler, which would execute the application;
  • Implement the application as a Window Service which would run 24/7, but only would perform the needed actions depending on the current time.

Which are the advantages/disadvantages of each approach?

Is there another way to do this?

Thanks in advance.

Amr
  • 1,935
  • 2
  • 19
  • 29
born to hula
  • 1,274
  • 5
  • 18
  • 36

4 Answers4

5

If it only executes once a day (or so) then just do it as a regular command line app that is executed by the windows task scheduler. Task scheduler already has all of the UI necessary to determine when to kick off the program, pass in parameters and anything else related to the scheduling of the task.

The only real reason to do this type of function as a windows service is if it needs higher execution resolution than once a minute. However, the main downside to a windows service is that you would have to manage the logic for how often/when to kick it off. Another one is that the app is always running, which leaves open the possibility for leaked memory if your code has issues.

NotMe
  • 87,343
  • 27
  • 171
  • 245
  • 2
    +1. My thoughts exactly. For a once per day task, the task scheduler is far easier and cleaner than working with a Timer in code. Writing services is a pain as well when it comes to troubleshooting - it's pretty hard to debug a service from within Visual Studio. (I'm sure there's a way, but I haven't found one as easy as simply running it in Visual Studio). Just from the coding/debugging perspective alone I'd shy away from a service in this case. Now, if it were once per minute o even hour, I may go the other route. – David Jul 22 '11 at 19:24
  • Building the application to be used by the Task Scheduler has the advantage of the ability of being used by other applications as well on demand. – Amr Jul 22 '11 at 19:28
1

On Unix/Linux you would use a cron job schedule a task to be executed. MS Windows' version is called the Task Scheduler and it is already a service that run 24/7 and performs the needed actions depending on the time.

Create a repeating task with the Task Scheduler to run your application. Creating, installing and configuring a service application is not exactly trivial. It's a much more involved process than creating a standard Forms or command line app and you don't need to do it anyway.

Paul Sasik
  • 79,492
  • 20
  • 149
  • 189
0

Another library that might be of interest is Quartz.NET

Sascha
  • 10,231
  • 4
  • 41
  • 65