windows 将应用程序作为服务运行的优势
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4785573/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Advantages of running an application as a service
提问by detunized
Sometimes I see that some applications allow themselves to be run as a service on Windows, for example Apache HTTP Serverallows that. I always ran it as a regular application and never experienced any problems or limitations.
有时我看到一些应用程序允许自己在 Windows 上作为服务运行,例如Apache HTTP Server允许. 我总是将它作为常规应用程序运行,从未遇到任何问题或限制。
- What are the advantages of this?
- Is there anything that applications is allowed to do or have when it's run as a service?
- What are the advantages for me as a developer, when I write a service vs. a regular application.
- 这有什么好处?
- 当应用程序作为服务运行时,是否允许应用程序执行或拥有任何内容?
- 作为开发人员,当我编写服务与常规应用程序时,我有哪些优势?
回答by Greg Hewgill
The biggest benefit to running an application as a service is that it will continue running even after the current user logs off (and will start running before a user logs on). Also, services normally run under a local "System" account instead of running under the login of a particular user (although services can, and often are, configured to run under a specific user login, usually dedicated to that purpose).
将应用程序作为服务运行的最大好处是,即使在当前用户注销后它仍会继续运行(并且会在用户登录之前开始运行)。此外,服务通常在本地“系统”帐户下运行,而不是在特定用户的登录名下运行(尽管服务可以并且经常被配置为在特定用户登录名下运行,通常专用于该目的)。
As a developer, you probably won't notice a lot of difference. Processes running on the desktop are usually easier to debug if something goes wrong. Normally you would set up your application to be able to run in either mode, making it both easy for development and appropriate for deployment.
作为开发人员,您可能不会注意到很多差异。如果出现问题,在桌面上运行的进程通常更容易调试。通常,您会将应用程序设置为能够在任一模式下运行,使其既易于开发又适合部署。
回答by ryan42
One thing that comes to my mind is that a service can start before a user logs into the system. I would consider a service to be the ideal way to run a daemon that does not normally have a frontend GUI. It's harder for a user to inadvertently quit, and its out of sight and out of mind.
我想到的一件事是服务可以在用户登录系统之前启动。我认为服务是运行通常没有前端 GUI 的守护进程的理想方式。用户更难在无意中退出,而且眼不见心不烦。
回答by John
Services run even when no user is logged on. Applications interact with users.
即使没有用户登录,服务也会运行。应用程序与用户交互。
If you need both, you may need to have two components, one running as a service and one interacting with users.
如果两者都需要,则可能需要有两个组件,一个作为服务运行,一个与用户交互。