c# windows服务 一个进程 多个服务的使用

来源:互联网 发布:阿莫达非尼 淘宝 编辑:程序博客网 时间:2024/05/22 13:46

网上看了好多关于这个的教程,关于单进程,多服务的说法和做法 有些是无法成功的,研究了三个小时,终于知道如何做了,写于此处,方便以后查阅。

1.新建服务工程–不多说,此时已有一个Service1.cs 
2.添加服务,此时多了一个Service2.cs 
3.Service1的设计界面添加安装程序 此时多了ProjectInstaller.cs 以及上面的两个控件:serviceProcessInstaller1,serviceInstaller1 不做任何改动 
4.Service2的设计界面添加安装程序 此时多了serviceInstaller2 控件 同样不做任何改动。 
5.在Service1,Service2的onStart内写自己的代码 
6.这个点比较重要 ProjectInstaller.Designer.cs内只有默认的

this.Installers.AddRange(new System.Configuration.Install.Installer[] {            this.serviceProcessInstaller1,            this.serviceInstaller1});

无serviceInstaller2 的信息 ,故添加:

this.Installers.AddRange(new System.Configuration.Install.Installer[] {            this.serviceProcessInstaller1,            this.serviceInstaller2});

然后就是安装了: 
bat 文件:安装 
%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\installutil.exe WindowService.exe 
pause 
卸载: 
%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\installutil.exe /u WindowService.exe 
pause

(版本信息之类的自己记得改 或者用其他方式 网上很多)

其实重点信息只有两个: 
1:第六点 加一段代码 
2:每个serviceProcessInstaller的serviceName是否对应

保留源代码,此处不知如何上传,有需要的可以联系:826575071

0 0
原创粉丝点击