zoukankan      html  css  js  c++  java
  • 构建简单Windows Service示例

    1. 示例源码:WindowsServiceSample
    2. ServiceHelper源码:ServiceHelper

    1. 创建Windows Service项目,如图:

    2. 配置服务参数

    3. 安装,启动,停止,卸载服务

    实现代码:

        private string ServicePath => txtServicePath.Text.Trim();
        private string ServiceName => "ServiceSample";
     
        private void BtnStart_Click(object sender, EventArgs e)
        {
            if (!ServiceHelper.IsExisted(ServiceName))
            {
                MessageBoxHelper.ShowError($"{ServiceName}不存在");
                return;
            }
     
            ServiceHelper.Start(ServiceName);
        }
     
        private void BtnStop_Click(object sender, EventArgs e)
        {
            if (!ServiceHelper.IsExisted(ServiceName))
            {
                MessageBoxHelper.ShowError($"{ServiceName}不存在");
                return;
            }
     
            ServiceHelper.Stop(ServiceName);
        }
     
        private void BtnInstall_Click(object sender, EventArgs e)
        {
            if (ServiceHelper.IsExisted(ServiceName))
            {
                MessageBoxHelper.ShowError($"{ServiceName}已经存在");
                return;
            }
     
            ServiceHelper.Install(ServicePath);
        }
     
        private void BtnUnInstall_Click(object sender, EventArgs e)
        {
            if (!ServiceHelper.IsExisted(ServiceName))
            {
                MessageBoxHelper.ShowError($"{ServiceName}不存在");
                return;
            }
     
            ServiceHelper.Uninstall(ServicePath);
        }
    }
    
  • 相关阅读:
    win8及win8.1商店出现0X80073CF9的解决办法!
    Ubuntu 14.04 登陆界面循环问题解决
    Java学习笔记-Json
    Java学习笔记-Thread-线程
    git学习笔记
    Java学习笔记-File
    java学习笔记-set
    C# 实验4 数据库
    C#文件处理
    C#-实验3
  • 原文地址:https://www.cnblogs.com/MeetYan/p/10897299.html
Copyright © 2011-2022 走看看