Topshelf允许开发者创建一个简单的控制台程序,将其安装为一个window服务。
这样做的原因很简单:方便调试。
使用命令行工具可以很方面的安装Topshelf创建的服务。
server.exe help
可以获得帮助信息(其中server.exe是创建的控制台的名字)
Topshelf入手很方便,具体可以参考官方文档
下面是官方的一个例子
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.RunAsLocalService(); x.SetDescription("Sample Topshelf Host"); x.SetDisplayName("Stuff"); x.SetServiceName("Stuff"); });}