C # windows service or just a regular program?

Possible duplicates:
Windows service and scheduled task
Windows Service Vs Simple Program

I am trying to create a program that runs periodically (say, every 5 minutes) or launches a program and runs it inside it (every 5 minutes).

The program should get data from the database when it is executed, and then write this (for now) to say the info.txt file (there are no sensitive things). every time he writes a file, he must overwrite existing information in the file.

The program should also start automatically when Windows starts. (therefore, there is no need to log into the computer and execute .exe [if this is a regular program, not a service])

In between the periods that he runs the program, there is nothing to do.

Therefore, should I run this program as a Windows service or use the task scheduler to periodically run the program for this? My goal is for this program to work as smoothly as possible without clogging up resources. (for example, it does not need more than 5% of the processor)

I hope my question was clear enough.

+7
source share
3 answers

I would go with an application that is launched by the task scheduler. The only thing you need to worry about is to run a separate instance of your application.

You can configure the task to run under a specific user account and run it even if the user is not logged in. There are many events that can trigger a task such as "Start Windows", "System Idle" ...

Another advantage is: If something fails, you can configure the task scheduler to send you an email or alert you in several ways. You can control the "exit code" of your application and signal the task scheduler about what is happening and what to do.

There are many good features that the task scheduler offers, but not many people use them.

+9
source

I would suggest a Windows service for this. It may be a good idea to create both and compare what resource use is anyway?

0
source

I would recommend for both, depending on the requirements of the task you want to run. I usually create most functions for scheduled services in a single class library and then port them to the console application for starters and debugging. When this is done, I will terminate it in the Windows service and forget about it.

Consideration for using the console application:

  • Make sure that you run it under the system account, if possible, or you can enter a specific login in the "Run" section, as in the scheduler. This ensures that interactive login is not required.
  • If having two instances running at the same time is a problem, make sure you name it clearly and check that the instance is running in your main method, and exit if there is one. Windows service will prevent this problem.

Consideration of using window service

  • Make sure you are educated from using streams. Windows services will use less resources when properly managed, but can be complicated if you don't need them, and end up with memory leaks in timer-based tasks.

.. there is much more to consider, but copy it correctly, and you can start with one and move on to the second when you are sure of it.

0
source

All Articles