使用.NET Core创建Windows服务(一) - 使用官方推荐方式(2)
发布时间:2021-01-07 09:26 所属栏目:52 来源:网络整理
导读:但是至少我们可以做如下了事情了。 static void Main(string[] args){ var loggingService = new LoggingService(); if (true) //Some check to see if we are in debug mode (Either #IF Debug etc or an app sett
但是至少我们可以做如下了事情了。 static void Main(string[] args) { var loggingService = new LoggingService(); if (true) //Some check to see if we are in debug mode (Either #IF Debug etc or an app setting) { loggingService.OnStartPublic(new string[0]); while(true) { //Just spin wait here. Thread.Sleep(1000); } //Call stop here etc. } else { ServiceBase.Run(new LoggingService()); } } 你的另一个选择是,在调试模式下进行项目发布,安装服务,然后附加调试器。实际上,这是Microsoft建议你使用的方式,但是我认为这简直一团糟。 后续实际上,我们可以在这里做一些其他非常有用的事情, 比如我们可以通过创建一个install.bat批处理文件来为我们运行SC Create命令。但我认为,上面我们看到的调试问题,已经让我不再想使用这种方式了。 幸运的是,有一个名为 (编辑:ASP站长网) |
相关内容
网友评论
推荐文章
热点阅读