热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

c#–Windows服务中的一个ServiceProcessInstaller中的多个ServiceInstaller

我在ServiceProcessInstaller中添加了两个ServiceInstallers.之后我改变了我的Main()如下:static void Main() { Ser

我在ServiceProcessInstaller中添加了两个ServiceInstallers.之后我改变了我的Main()如下:

static void Main()
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new Service1(),
new Service2()
};
ServiceBase.Run(ServicesToRun);
}

我还在Service1上将Service2设置为依赖服务,如下所示:

private void InitializeComponent()
{
this.Service1ProcessInstaller = new System.ServiceProcess.ServiceProcessInstaller();
this.Service1Installer = new System.ServiceProcess.ServiceInstaller();
this.Service2Installer = new System.ServiceProcess.ServiceInstaller();
//
// Service1ProcessInstaller
//
this.Service1ProcessInstaller.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
this.Service1ProcessInstaller.Password = null;
this.Service1ProcessInstaller.Username = null;
//
// Service1Installer
//
this.Service1Installer.ServiceName = "Service1";
this.Service1Installer.ServicesDependedOn = new string[] {"Service2"};
//
// Service2Installer
//
this.Service2Installer.ServiceName = "Service2";
//
// ProjectInstaller
//
this.Installers.AddRange(new System.Configuration.Install.Installer[] {
this.Service1ProcessInstaller,
this.Service1Installer,
this.Service2Installer});
}

它仍然只运行我的Service1.

Service2永远不会打电话.

如果我在Main()中更改序列,则Service2仅调用.

它总是呼叫第一个服务.

如何拨打我的两项服务?

解决方法:

我找到了解决方案.问题不在于卸载时的依赖服务.我已经卸载了我的服务然后再次安装它然后我在我的Services.msc中找到了这两个服务.

当它们实际上彼此依赖时我们需要依赖服务,所以我也删除了相关的服务代码.

现在我可以手动启动它们.它们都在运行.下面是我成功运行的代码.

static void Main()
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new Service1(),
new Service2()
};
ServiceBase.Run(ServicesToRun);
}
private void InitializeComponent()
{
this.Service1ProcessInstaller = new System.ServiceProcess.ServiceProcessInstaller();
this.Service1Installer = new System.ServiceProcess.ServiceInstaller();
this.Service2Installer = new System.ServiceProcess.ServiceInstaller();
//
// Service1ProcessInstaller
//
this.Service1ProcessInstaller.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
this.Service1ProcessInstaller.Password = null;
this.Service1ProcessInstaller.Username = null;
//
// Service1Installer
//
this.Service1Installer.ServiceName = "Service1";
//
// Service2Installer
//
this.Service2Installer.ServiceName = "Service2";
//
// ProjectInstaller
//
this.Installers.AddRange(new System.Configuration.Install.Installer[] {
this.Service1ProcessInstaller,
this.Service1Installer,
this.Service2Installer});
}


推荐阅读
  • 本文介绍了如何使用C#制作Java+Mysql+Tomcat环境安装程序,实现一键式安装。通过将JDK、Mysql、Tomcat三者制作成一个安装包,解决了客户在安装软件时的复杂配置和繁琐问题,便于管理软件版本和系统集成。具体步骤包括配置JDK环境变量和安装Mysql服务,其中使用了MySQL Server 5.5社区版和my.ini文件。安装方法为通过命令行将目录转到mysql的bin目录下,执行mysqld --install MySQL5命令。 ... [详细]
  • 本文介绍了在rhel5.5操作系统下搭建网关+LAMP+postfix+dhcp的步骤和配置方法。通过配置dhcp自动分配ip、实现外网访问公司网站、内网收发邮件、内网上网以及SNAT转换等功能。详细介绍了安装dhcp和配置相关文件的步骤,并提供了相关的命令和配置示例。 ... [详细]
  • 本文分享了一个关于在C#中使用异步代码的问题,作者在控制台中运行时代码正常工作,但在Windows窗体中却无法正常工作。作者尝试搜索局域网上的主机,但在窗体中计数器没有减少。文章提供了相关的代码和解决思路。 ... [详细]
  • 本文介绍了Oracle数据库中tnsnames.ora文件的作用和配置方法。tnsnames.ora文件在数据库启动过程中会被读取,用于解析LOCAL_LISTENER,并且与侦听无关。文章还提供了配置LOCAL_LISTENER和1522端口的示例,并展示了listener.ora文件的内容。 ... [详细]
  • 解决VS写C#项目导入MySQL数据源报错“You have a usable connection already”问题的正确方法
    本文介绍了在VS写C#项目导入MySQL数据源时出现报错“You have a usable connection already”的问题,并给出了正确的解决方法。详细描述了问题的出现情况和报错信息,并提供了解决该问题的步骤和注意事项。 ... [详细]
  • 怎么在PHP项目中实现一个HTTP断点续传功能发布时间:2021-01-1916:26:06来源:亿速云阅读:96作者:Le ... [详细]
  • 导出功能protectedvoidbtnExport(objectsender,EventArgse){用来打开下载窗口stringfileName中 ... [详细]
  • Imtryingtofigureoutawaytogeneratetorrentfilesfromabucket,usingtheAWSSDKforGo.我正 ... [详细]
  • 如何自行分析定位SAP BSP错误
    The“BSPtag”Imentionedintheblogtitlemeansforexamplethetagchtmlb:configCelleratorbelowwhichi ... [详细]
  • 安装mysqlclient失败解决办法
    本文介绍了在MAC系统中,使用django使用mysql数据库报错的解决办法。通过源码安装mysqlclient或将mysql_config添加到系统环境变量中,可以解决安装mysqlclient失败的问题。同时,还介绍了查看mysql安装路径和使配置文件生效的方法。 ... [详细]
  • 搭建Windows Server 2012 R2 IIS8.5+PHP(FastCGI)+MySQL环境的详细步骤
    本文详细介绍了搭建Windows Server 2012 R2 IIS8.5+PHP(FastCGI)+MySQL环境的步骤,包括环境说明、相关软件下载的地址以及所需的插件下载地址。 ... [详细]
  • Centos7.6安装Gitlab教程及注意事项
    本文介绍了在Centos7.6系统下安装Gitlab的详细教程,并提供了一些注意事项。教程包括查看系统版本、安装必要的软件包、配置防火墙等步骤。同时,还强调了使用阿里云服务器时的特殊配置需求,以及建议至少4GB的可用RAM来运行GitLab。 ... [详细]
  • 本文介绍了[从头学数学]中第101节关于比例的相关问题的研究和修炼过程。主要内容包括[机器小伟]和[工程师阿伟]一起研究比例的相关问题,并给出了一个求比例的函数scale的实现。 ... [详细]
  • Windows下配置PHP5.6的方法及注意事项
    本文介绍了在Windows系统下配置PHP5.6的步骤及注意事项,包括下载PHP5.6、解压并配置IIS、添加模块映射、测试等。同时提供了一些常见问题的解决方法,如下载缺失的msvcr110.dll文件等。通过本文的指导,读者可以轻松地在Windows系统下配置PHP5.6,并解决一些常见的配置问题。 ... [详细]
  • 本文介绍了在Windows环境下如何配置php+apache环境,包括下载php7和apache2.4、安装vc2015运行时环境、启动php7和apache2.4等步骤。希望对需要搭建php7环境的读者有一定的参考价值。摘要长度为169字。 ... [详细]
author-avatar
mobiledu2502929697
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有