日期:2014-05-17 浏览次数:21319 次
try
{
ServiceController serviceGprs = new ServiceController("GprsService");
string serviceState = serviceGprs.Status.ToString();
//最近一条数据与当前时间的时间差
int timeDiff = Helper.GetLastData();
if (serviceState.Equals("Stopped"))
{
timer.Enabled = false;
serviceGprs.Start();
//等待
Helper.AddLog("GprsService异常终止,正在重新启动!");
serviceGprs.WaitForStatus(ServiceControllerStatus.Running);
Helper.AddLog("GprsService异常终止,启动完毕!");
timer.Interval = outTime * 60 * 1000;
timer.Enabled = true;
}
else if (timeDiff > outTime)
{
timer.Enabled = false;
//等待
Helper.AddLog("GprsService没有响应,正在停止服务!");
serviceGprs.Stop();
serviceGprs.WaitForStatus(ServiceControllerStatus.Stopped);
Helper.AddLog("服务已经停止,正在重新启动服务!");
serviceGprs.Start();
&