我发现自己处于一个糟糕的境地,我有一个topshelf服务,它使用的是一个存在内存问题的c++库。由于我对自己所处位置的这种痴迷,我想在它的活动暂停期间不时地调用TopShelf来重新启动它,没有其他原因,只是为了“让世界再次变得正确”。
有没有允许这样做的TopShelf API?我似乎在文档中找不到任何东西。
发布于 2018-12-06 17:33:22
当您想要重新启动服务时调用Environment.Exit(1);
然后在HostFactory中添加Enable ServiceRecovery
HostFactory.Run(configure =>
{
configure.Service((ServiceConfigurator<Service> service) =>
{
service.WhenStarted(s => s.Start());
service.WhenStopped(s => s.Stop());
});
//Setup Account that window service use to run.
configure.RunAsNetworkService();
configure.SetServiceName("ServiceName");
configure.SetDisplayName("ServiceName");
configure.SetDescription("Description");
configure.StartAutomaticallyDelayed();
configure.EnableServiceRecovery(recoveryOption =>
{
recoveryOption.RestartService(0);
});
});发布于 2014-07-30 16:18:10
我敢肯定Topshelf不支持这一点,所以你必须自己从代码开始做这件事。
看一下ServiceController类。
最坏的情况是,你可以有第二个简单的topshelf安装程序来管理你当前的服务并重新启动它?(我知道有点脏)
https://stackoverflow.com/questions/24915082
复制相似问题