I find myself in a terrible situation where I have a topshelf service that uses a c++ library with memory issues. Because of this obination of a place I find myself in, I want to call TopShelf to restart the service every now and then during a pause in it's activities for no other reason but to "make the world right again".
Are there any TopShelf APIs that allow for this? I cannot seem to find any in the documentation.
call Environment.Exit(1);
when u want restart service
then in HostFactory add 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);
});
});
I am sure Topshelf doesn't support this so you would have to do this from code yourself.
Take a look at the ServiceController class.
Worst case you could have a second simple topshelf installer that manages your current service and restarts it? (bit dirty i know)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.