zoukankan      html  css  js  c++  java
  • C# windows服务(一) 创建

    新建服务项目

      

    双击Service1.cs,出现界面,右键,选择 添加安装程序

      

    项目中会生成 ProjectInstaller.cs,

      

     修改ProjectInstaller.cs代码:

      

                // 设置运行该服务应用程序时所使用的帐户类型,(默认account,服务安装的时候会提示输入用户名密码)
                this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalService;
    
                // 设定服务名称
                this.serviceInstaller1.ServiceName = "GZPlanService";
                // 服务描述
                this.serviceInstaller1.Description = "GZ计划管理服务";
                // 设定服务的启动方式 自动启动
                this.serviceInstaller1.StartType = System.ServiceProcess.ServiceStartMode.Automatic;

    修改好后回头,写入自己想要的操作。Service1.cs出现设计界面,双击设计界面进入cs代码页。可以重写这些方法

      

      public partial class Service1 : ServiceBase
        {
            public Service1()
            {
                InitializeComponent();
            }
            // 服务开启执行代码
            protected override void OnStart(string[] args)
            {
            }
    
            // 服务结束执行代码
            protected override void OnStop()
            {
            }
    
            // 服务暂停执行代码
            protected override void OnPause()
            {
                base.OnPause();
            }
            // 服务恢复执行代码
            protected override void OnContinue()
            {
                base.OnContinue();
            }
            // 系统即将关闭执行代码
            protected override void OnShutdown()
            {
                base.OnShutdown();
            }
        }
  • 相关阅读:
    一次网络IO优化的讨论
    服务器框架回顾
    一个小工具:DebugFile
    TPO-23 C2 Advice on choosing courses
    TPO-23 C1 Post a student announcement
    TPO-22 C2 Revise a music history paper
    TPO-22 C1 Complain about a biased article
    TPO-21 C2 Which elective courses to take
    TPO-20-Apply for the undergraduate research fund
    TPO-21 C1 Find a building for orientation
  • 原文地址:https://www.cnblogs.com/GarsonZhang/p/13935816.html
Copyright © 2011-2022 走看看