【发布时间】:2011-02-26 14:47:53
【问题描述】:
任何人都可以帮助我...我如何在 c#.net 中每 15 分钟以编程方式重新启动我的窗口服务,请帮助我.. 我已经在我的代码中完成了diz方式 我一直喜欢这种方式,直到在课堂页面[RunInstaller(true)]
public class ProjectInstaller : System.Configuration.Install.Installer
private System.ServiceProcess.ServiceProcessInstaller
serviceProcessInstaller1;
private System.ServiceProcess.ServiceInstaller serviceInstaller1;
public ProjectInstaller()
InitializeComponent();
}
private void InitializeComponent()
{
this.serviceProcessInstaller1 =
new System.ServiceProcess.ServiceProcessInstaller();
this.serviceInstaller1 =
new System.ServiceProcess.ServiceInstaller();
this.serviceProcessInstaller1.Account =
System.ServiceProcess.ServiceAccount.LocalSystem;
this.serviceProcessInstaller1.Password = null;
this.serviceProcessInstaller1.Username = null;
this.serviceInstaller1.ServiceName = "MyNewService";
this.serviceInstaller1.StartType =
System.ServiceProcess.ServiceStartMode.Automatic;
this.Installers.AddRange
(new System.Configuration.Install.Installer[]
{
this.serviceInstaller1,
this.serviceInstaller1});
}
}
【问题讨论】:
-
为什么需要每 15 分钟重新启动一次?如果您希望代码每 15 分钟运行一次,请使用计时器并将计时器
Tick事件设置为应该运行的代码。 -
每 15 分钟重新启动一次服务听起来像是在尝试解决其他问题。究竟为什么要重新启动服务?服务被设计为长时间连续运行,如果这不是您想要的,服务可能是该工作的错误工具。
-
顺便问一下,您的 Windows 服务与您标记问题的 asp.net 标记有什么关系?如果与问题无关,则应删除该标签。
-
@albin ...谢谢你的回答是的!在一个特定的根文件夹中,一些文件会来来去去,我的服务将很好地开始工作,一段时间后,工作现在再次完成,一些文件将在那个特定的时间到达那个根文件夹,我通过手动重启来完成,这样我在问