前面讲了如何使用Topshelf 快速开发windows服务, 不清楚的可以看之前的这篇文章:https://www.toutiao.com/i6774202377504293389/ ,今天说一说Topshelf 的相关配置。
Topshelf Configuration 简单配置
官方文档,对HostFactory 里面的参数做了详细的说明:http://docs.topshelf-project.com/en/latest/configuration/config_api.html ,下面只对一些常用的方法进行简单的解释:
我们将上面的程序代码改一下:
HostFactory.Run(x => //1 { x.Service(s => //2 { s.ConstructUsing(name => new TownCrier()); //配置一个完全定制的服务,对Topshelf没有依赖关系。常用的方式。 //the start and stop methods for the service s.WhenStarted(tc => tc.Start()); //4 s.WhenStopped(tc => tc.Stop()); //5 }); x.RunAsLocalSystem();