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

  • 相关阅读:
    cf C. Vasya and Robot
    zoj 3805 Machine
    cf B. Vasya and Public Transport
    cf D. Queue
    cf C. Find Maximum
    cf B. Two Heaps
    cf C. Jeff and Rounding
    cf B. Jeff and Periods
    cf A. Jeff and Digits
    I Think I Need a Houseboat
  • 原文地址:https://www.cnblogs.com/kingteach/p/1992313.html
Copyright © 2011-2022 走看看