创建窗口服务的启动之间的依赖 [英] create dependency between windows services startup

查看:172
本文介绍了创建窗口服务的启动之间的依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创造它被设置为自动启动Windows服务。此服务连接到在启动数据库服务。问题是数据库服务似乎开始我的售后服务。是否有一个编程的方式来使数据库服务已经启动后,我的服务启动定义这种依赖性。

I have created a windows service which is set to start automatically. This service connects to the database service on startup. The issue is the database service seems to start after my service. Is there is a programmatic way to define this dependency so that my service starts after the database service has started.

我发现这篇文章<一个href="http://www.boyce.us/windows/servertipcontent.asp?ID=7">http://www.boyce.us/windows/servertipcontent.asp?ID=7其中谈到有关添加注册表项以做到这一点。我想知道是否有一个C#的方式来做到这一点?

I found this article http://www.boyce.us/windows/servertipcontent.asp?ID=7 which talks about adding a registry entry to do that. I would like to know if there is a C# way to do this?

更新:

添加到上面的问题。这是另一种情况。的服务是使用installshied其不需要一个projectinsaller正在安装。这似乎InstallShield将查找类从ServiceBase类派生并安装每个服务。如何增加的依赖于这样的情况?

Adding to the above question. Here is another scenario. The services are being installed using installshied which does not need a projectinsaller. It seems installshield looks for classes deriving from ServiceBase class and installs each service. How to add the dependency in such a scenario?

推荐答案

您正在寻找的<一个href="http://msdn.microsoft.com/en-us/library/system.serviceprocess.serviceinstaller.servicesdependedon%28v=VS.100%29.aspx">ServiceInstaller.ServicesDependedOn物业为您的项目的ServiceInstaller组成部分。

You're looking for the ServiceInstaller.ServicesDependedOn Property for your project's ServiceInstaller component.

从文章的注释部分(我加粗你感兴趣的部分):

From the article's Remarks section (and I bolded the part you're interested in):

一个服务可能需要其他服务   在运行之后,才能开始。该   从这个属性信息   写入到注册表中的一个关键。什么时候   用户(或系统,在的情况下   自动启动),尝试运行   服务,服务控制管理器   (SCM)验证每个的   阵列中的服务已经被   开始了。

A service can require other services to be running before it can start. The information from this property is written to a key in the registry. When the user (or the system, in the case of automatic startup) tries to run the service, the Service Control Manager (SCM) verifies that each of the services in the array has already been started.

如果阵列中的任何服务   运行以后,SCM将尝试启动   他们。这包括与服务   手动StartType

If any service in the array is not running then, the SCM tries to start them. This includes services with Manual StartType.

如果任何服务后,此服务   时刻依赖无法启动,此服务   将无法启动。一个例外是不   如果未启动,系统引发   因为没有异常处理   在系统级,以检测此。   决定如何处理服务开始   失败和在实现这个你   code。通常情况下,会出现一个对话框   在启动时,如果服务失败的用户   启动。

If any service upon which this service depends fails to start, this service will not start. An exception is not thrown if the system is not started because there is no exception handling at the system level to detect this. Decide how to handle service start failures and implement this in your code. Typically, a dialog appears to the user at startup if a service fails to start.

如果该服务没有启动,一   条目被写入应用程序   事件日志。

If the service does not start, an entry is written to the Application event log.

该服务后,此服务   取决于不需要在同一   可执行文件。

The services upon which this service depends do not need to be in the same executable.

这篇关于创建窗口服务的启动之间的依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆