繁体   English   中英

在Topshelf服务中重新启动self

[英]Restarting self in a Topshelf service

我正在使用Topshelf来托管Windows服务。 我希望让托管服务调用以在某些事件时重新启动。 我想知道如何实现这一目标?

谢谢,本

如果您知道要重新调用的服务名称,则可以使用服务管理器。 它本身可能会或可能不会起作用。 这不是Topshelf所暴露的,所以你可以自己动手去做。

调用Environment.Exit(1); 当你想重启服务

然后在HostFactory中添加启用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);
                });

            });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM