What is the benefit of developing the application as a windows service?

前端 未结 4 796
[愿得一人]
[愿得一人] 2021-01-03 22:31

I am going to develop an application which will process online data (comming through socket) and it does not need any user interaction.

I am thinking of a simple con

相关标签:
4条回答
  • 2021-01-03 22:49
    1. You can manage a service from another machine (start/stop)
    2. As services write to the event log you can also monitor the service from another machine (although nothing stops you from doing this from a regular application)
    3. No one has to be logged on for the service to run
    0 讨论(0)
  • 2021-01-03 22:55

    In fact, it really depends on the usage of your application, I think.

    For example, if you only need to run your processing at a specific time, the usage of the command line can be enough.

    The windows service will be really interesting if your process need to run continuously, and silently (no user interaction).

    You can also consider the task scheduling in Windows. Basically, it will run your application (through a .bat file for example) at specified times. It can be helpfull if your application needs to be run every day at 02:00 for example... In "Control Panel", you have an option "Scheduled Tasks". Then, you click on "Add Scheduled Task", and follow the wizard...

    0 讨论(0)
  • 2021-01-03 23:01

    On the top of my head:

    • You can control the user (and the rights associated with this user account) which starts the process
    • an Automatically started process means the desktop need to be on, not user logged, for the service to run
    • a policy on failure can be defined (try to restart n times run a specific program if fails)
    • a dependency can be defined (if you depend on other sevices)
    • you can wrap your scrip in an invisible windows
    • you can easily start/stop/restart the script (net start <scriptname>)
    0 讨论(0)
  • 2021-01-03 23:06

    I can't add anything to VonC's list but I would add that if you're using the usual Microsoft tools (VS & .net) it's easy to do both.

    I create a class library that contains all my application logic and a MyServer class which has .Start() and .Stop() methods. You can then create both a console app and winservice app that both reference this. E.g. the console App instantiates a new MyServer, calls Start, waits for a key press and calls Stop.

    I use the console app during development and the windows service for deployment.

    0 讨论(0)
提交回复
热议问题