zoukankan      html  css  js  c++  java
  • c#Windows服务

    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文件

  • 相关阅读:
    3秒后页面跳转代码
    数据库 ""和null的在java 持久化中的区别
    去掉标签元素
    hibernate 自动封装
    hql 多对多查询
    javascript 数组
    spring mvc+mybatis整合
    collection映射
    mybatis中one2many
    mybatis中many2one
  • 原文地址:https://www.cnblogs.com/kingteach/p/1992313.html
Copyright © 2011-2022 走看看