2009-12-06 211 views
0

有没有什么办法可以像Windows窗体中的Application.Restart()一样从同一服务重新启动Windows服务,我不想从服务启动另一个进程来重新启动服务。从服务重新启动Windows服务

+1

已经在这里解答:http://stackoverflow.com/questions/220382/how-can-a-windows-service-programmatically-restart-itself – bobbymcr 2009-12-06 17:32:33

回答

1

我是一个名为Daemoniq的开源Windows服务托管框架的开发人员。 Setting service recovery options是它的一个特点。您可以从http://daemoniq.org

当前功能下载包括:通过的app.config

  • 运行通过CommonServiceLocator
  • 设置常用的服务像服务名,显示名,描述和serviceStartMode性能

    • 容器无关的服务位置通过的app.config
    • 组服务
    • 一套恢复选项在同一进程的多个窗口服务通过命令行通过命令行
    • 安装,卸载,调试服务通过的app.config
    • 一套服务流程凭据依靠

    谢谢!

  • 0

    您还可以在安装项目中将Custom Action添加到Custom Actions的Commit文件夹中。它必须是具有[RunInstaller(true)]属性的从System.Configuration.Install.Installer继承的类的类库项目的主输出。在这个类,你需要重写一个基本方法:

    public override void Commit(IDictionary savedState) 
        { 
         base.Commit(savedState); 
         ProcessStartInfo psi = new ProcessStartInfo("sc", "failure \"You service name\" reset= 60 actions= restart/1000"); 
         psi.CreateNoWindow = true; 
         Process proc = Process.Start(psi); 
         proc.WaitForExit(); 
        } 
    

    它的配置为您服务,失败后重新启动automaticaly。

    比当你需要重新启动你的服务,你可以做

    Environment.FailFast("Self restarting service..."); 
    

    但它有一个缺点 - 它会被解雇的事件日志中的错误消息。