c# – Windows服务中的一个ServiceProcessInstaller中的多个ServiceInstaller
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c# – Windows服务中的一个ServiceProcessInstaller中的多个ServiceInstaller,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2521字,纯文字阅读大概需要4分钟。
内容图文
![c# – Windows服务中的一个ServiceProcessInstaller中的多个ServiceInstaller](/upload/InfoBanner/zyjiaocheng/964/8216916e6974431e89714cf8b148c453.jpg)
我在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# – Windows服务中的一个ServiceProcessInstaller中的多个ServiceInstaller全部内容,希望文章能够帮你解决c# – Windows服务中的一个ServiceProcessInstaller中的多个ServiceInstaller所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。