[英]Restarting a c# TopShelf service programmatically
我發現自己處於一個糟糕的境地,我有一個使用帶有內存問題的c ++庫的topshelf服務。 由於我發現自己所處的這個地方,我想讓TopShelf一次又一次地重新啟動服務,暫停它的活動,除了“讓世界再次正確”之外別無其他原因。
是否有任何TopShelf API允許這樣做? 我似乎無法在文檔中找到任何內容。
調用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);
});
});
我確信Topshelf不支持這個,所以你必須自己從代碼中做到這一點。
看一下ServiceController類。
最壞的情況是你可以有第二個簡單的topshelf安裝程序來管理你當前的服務並重新啟動它? (我知道有點臟)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.