-1
我正在写一个Windows服务,检查特定服务并检查它。如果是停止将开始它...启动Windows服务
protected override void OnStart(string[] args)
{
Thread thread = new Thread(new ThreadStart(ServiceThreadFunction));
thread.Start();
}
public void ServiceThreadFunction()
{
try
{
ServiceController dc = new ServiceController("WebClient");
//ServiceController[] services = ServiceController.GetServices();
while (true)
{
if ((int)dc.Status == 1)
{
dc.Start();
WriteLog(dc.Status.ToString);
if ((int)dc.Status == 0)
{
//heartbeat
}
}
else
{
//service started
}
//Thread.Sleep(1000);
}
}
catch (Exception ex)
{
// log errors
}
}
我希望服务检查其他业务,并开始... plz帮助我,我怎么能做到这一点
你使用的代码有什么问题?哪里出问题了? – 2012-01-30 13:08:56
为什么你将枚举转换为整数而不是直接与适当的枚举值进行比较?这会让这个更具可读性。 – 2012-01-30 13:12:15