[英]What is the difference between a windows service and a regular application?
I have only created regular windows applications (C# mostly). 我只创建了常规的Windows应用程序(主要是C#)。 What differentiates a windows service from a regular windows application?
Windows服务与常规Windows应用程序的区别是什么? What makes them different?
是什么让他们不同? What can a service do that an application can't?
应用程序无法提供哪些服务? What are the differences seen from a developers point of view?
从开发人员的角度看有哪些不同之处? How do you create one?
你是如何创造一个的? Is it just to create a regular application (Console application maybe, since there are no gui?) and run or install it in a special way, or is it more that has to be done?
它只是创建一个常规应用程序(可能是控制台应用程序,因为没有gui?)并以特殊方式运行或安装它,还是需要做更多的事情?
There are a couple of things that jump out to me immediately. 有一些事情立即向我跳出来。
This MSDN page leads to more documentation on creating them than you could shake a stick at. 这个MSDN页面提供了更多关于创建它们的文档,而不是你可以动摇一下。 This page is perhaps a better introduction to them in general.
这个页面可能是对它们的更好的介绍。
The key difference between a process running as an app versus as a service is that the service can operate entirely outside the normal association with a user and session. 作为应用程序运行的进程与作为服务运行的进程之间的主要区别在于,服务可以完全在与用户和会话的正常关联之外运行。 Thus services can run such that they start before any user logs in and can continue running after users log off.
因此,服务可以运行,以便它们在任何用户登录之前启动,并且可以在用户注销后继续运行。 Services are thus used to implement a great deal of the actual functionality of the operating system.
因此,服务用于实现操作系统的大量实际功能。
Services are also not tied to running as a 1:1 mapping with a process. 服务也不依赖于与进程的1:1映射运行。 Many services can exist within one process, normally through the use of svchost (take a look at these with process explorer for an indication of how this often works).
许多服务可以存在于一个进程中,通常通过使用svchost(使用进程资源管理器查看这些服务,以指示这通常如何工作)。 This reduces the effort at startup as multiple processes are not required for relatively lightweight services.
这减少了启动时的工作量,因为相对轻量级的服务不需要多个进程。
Implementing a service in c# is pretty simple, this page indicates how in very easy to follow terms. 在c#中实现服务非常简单,这个页面表明了如何非常容易地遵循术语。
Note that in reality a service in windows is little more that the scaffolding in the registry under HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Services which defines those 'image paths' (in most cases simply executables and the parameters to use) which are considered services along with which user then run as, which other services they depend on and whether they start at start up/post start up or as required. 请注意,实际上,Windows中的服务仅仅是HKEY_LOCAL_MACHINE \\ System \\ CurrentControlSet \\ Services下的注册表中的脚手架,它定义了那些被视为服务的“图像路径”(在大多数情况下只是可执行文件和要使用的参数)。然后,哪个用户运行,他们依赖哪些其他服务,以及他们是在启动/启动后启动还是根据需要启动。
If you're familiar with Unix, a Windows service is like a Unix daemon. 如果你熟悉Unix,那么Windows服务就像一个Unix守护进程。 It isn't associated with any particular user, and is always running in the background.
它与任何特定用户无关,并且始终在后台运行。
The main difference is that a windows service is something you want to run as a background service and doesn't require a UI. 主要区别在于,您希望将Windows服务作为后台服务运行,而不需要UI。 An example is a service that indexes files on your drive for searching.
一个示例是一个索引驱动器上的文件以进行搜索的服务。
Another benefit is you can have services automatically start when the user logs in. 另一个好处是您可以在用户登录时自动启动服务。
There are also methods you can override that are called when the service is started/stopped (ie. from Control Panel | Administrative Tools | Services). 还有一些方法可以覆盖在服务启动/停止时调用的方法(即从“控制面板”|“管理工具”|“服务”)。
Within Visual Studio there is a special project type you can use to create it. 在Visual Studio中,有一个特殊的项目类型可用于创建它。 See the site below for an example: http://www.dotheweb.net/articles/dotnet/services.aspx
请参阅以下网站以获取示例: http : //www.dotheweb.net/articles/dotnet/services.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.