你的位置:首页 > ASP.net教程

[ASP.net教程]Topself


  • TopShelf简介

    个人理解:开源、跨平台的服务框架。提供一种方式以控制台编写windows服务,与windows服务相比,目前只发现便于调试。

    官网网站:http://docs.topshelf-project.com/en/latest/index.html

  • TopShelf基本用法

    借用topshelf官网用例:

public class TownCrier  {    readonly Timer timer;    public TownCrier()    {      timer = new Timer(1000) { AutoReset = true };      timer.Elapsed += (sender, eventArgs) => Console.WriteLine("It is {0} and all is well", DateTime.Now);    }    public void Start() { timer.Start(); }    public void Stop() { timer.Stop(); }  }  public class Program  {    public static void Main(string[] args)    {      HostFactory.Run(x =>        {          x.Service<TownCrier>(s =>          {            s.ConstructUsing(name => new TownCrier());            s.WhenStarted(tc => tc.Start());            s.WhenStopped(tc => tc.Stop());          });          x.RunAsLocalSystem();          x.SetDescription("sample Topshelf Host");          x.SetDisplayName("stuff");          x.SetServiceName("Stuff");        });    }  }

 

  • TopShelf安装与卸载

    CMD进入控制台程序根目录执行   “控制台运行程序名 install”和“控制台运营程序名 uninstall”进行安装和卸载。

http://docs.topshelf-project.com/en/latest/index.html