zoukankan      html  css  js  c++  java
  • 使用Topshelf管理Windows服务

     
    一、官方网站及源码下载
          1、官方网站:http://topshelf-project.com/
     
    二、Topshelf优势
          1、调试方便:不用创建windows服务项目,直接创建控制台程序即可,启动控制台就可以进行服务代码调试
          2、安装/卸载服务方法
               1、cmd-->cd 程序目录(直接定位到exe文件所在目录)
          windows 7   cd C:
                 Widows Serve  cd /d C:
               2、安装服务:JwifiRoute.Message.LogServices.exe install
               3、启动服务:JwifiRoute.Message.LogServices.exe start
               4、卸载服务(需要执行多次才能卸载服务):JwifiRoute.Message.LogServices.exe uninstall
     
    三、使用Topshelf创建服务
           1、引入Topshelf.dll
           2、启动服务
             
            /// <summary>
            /// 应用程序的主入口点。
            /// </summary>
            static void Main()
            {
                HostFactory.Run(c =>
                {
                    c.SetServiceName("LogServices");
                    c.SetDisplayName("LogServices");
                    c.SetDescription("LogServices");
    
                    c.Service<TopshelfService>(s =>
                    {
                        s.ConstructUsing(b => new TopshelfService());
                        s.WhenStarted(o => o.Start());
                        s.WhenStopped(o => o.Stop());
                    });
                });
              3、服务程序逻辑
    public class TopshelfService
          {
            public void Start()
            {
                //服务逻辑
            }
    
     public void Stop()
            {
            }
    }
  • 相关阅读:
    C#-项目属性设置
    SQL--连接字符串总结
    希尔排序实现(不太满意)
    选择排序实现
    用位运算实现 | 与 ^ 的功能
    如何初始化一个定长List<T>
    线程池与Threadlocal
    常用类
    基本数据类型介绍
    eclipse快捷键
  • 原文地址:https://www.cnblogs.com/gossip/p/4506142.html
Copyright © 2011-2022 走看看