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

    目的:以控制台方式开发Windows服务程序,调试部署方便。

    https://www.cnblogs.com/itjeff/p/8316244.html

    https://www.cnblogs.com/gossip/p/4506142.html

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Topshelf;

    namespace Topshelf测试
    {
        //用控制台方式开发Windows服务,使用开源组件Topshelf做托管
        //主要目的:调试方便

        //https://www.cnblogs.com/itjeff/p/8316244.html
        //
        //安装:TopshelfDemo.exe install
        //启动:TopshelfDemo.exe start
        //卸载:TopshelfDemo.exe uninstall

        class Program
        {
            static void Main(string[] args)
            {

                HostFactory.Run(c =>
                {
                    c.SetServiceName("LogServices");
                    c.SetDisplayName("LogServices");
                    c.SetDescription("LogServices");
                    c.RunAsLocalSystem();

                    c.Service<TopshelfService>(s =>
                    {
                        s.ConstructUsing(b => new TopshelfService());
                        s.WhenStarted(o => o.Start());
                        s.WhenStopped(o => o.Stop());
                        s.WhenPaused(o => o.Pause());
                        s.WhenContinued(o => o.Continue());
                        s.WhenShutdown(o => o.Shutdown());
                    });
                });
            }
        }


        public class TopshelfService
        {
            public void Start()
            {
                //服务逻辑
            }

            public void Stop()
            {
            }

            public void Pause()
            {
            }

            public void Continue()
            {
            }

            public void Shutdown()
            {
            }
        }
    }

  • 相关阅读:
    我告诉你 电脑软件工具
    mysql 查询当天、本周,本月,上一个月的数据
    springboot:springboot+mybatis多数据源最简解决方案
    MySQL数据库优化的(经典必看)
    MyBatis 的强大特性之一便是它的动态 SQL之常用属性使用
    你知道Spring 中使用了哪些设计模式?
    kafka 相关面试问题
    掌握TCP/IP的通信原理(三次握手、四次挥手)。
    jsp和servlet实现文件的上传和下载
    Java获取数据库记录通过javabean映射,并存入list集合
  • 原文地址:https://www.cnblogs.com/81/p/10106560.html
Copyright © 2011-2022 走看看