文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>c#Windows服务

c#Windows服务

时间:2011-03-23  来源:KingNet

1.vs ->Windows服务



2.创建完成后在项目下默认会创建 Program.cs 和 Service1.cs

双击Service1.cs到设计,在设计区右击,选择添加安装程序

产生2个组建

点击ServiceInstaller1 设置相关属性

3.在Service1.cs 事件:

 protected override void OnStart(string[] args)        {        }服务开启时
 protected override void OnStop()        {        }服务停止时

要想在程序安装时自动启动服务:

在ProjectInstaller.cs里:

 public ProjectInstaller()
{
InitializeComponent();
this.Committed += new InstallEventHandler(ProjectInstall_Committed);
}
private void ProjectInstall_Committed(object obj, InstallEventArgs eventArgs)
{
System.ServiceProcess.ServiceController controller
= new ServiceController("服务名");
controller.Start();
}

4.编译后在Debug里的.exe 不是双击执行,要在C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe 来执行编译后的exe文件

相关阅读 更多 +
排行榜 更多 +
mirrox模组(玩家自制)手机版下载

mirrox模组(玩家自制)手机版下载

休闲益智 下载
集装箱模拟器手机版下载安装

集装箱模拟器手机版下载安装

模拟经营 下载
哔咔漫画app下载免费2025

哔咔漫画app下载免费2025

浏览阅读 下载