【发布时间】:2014-08-05 08:52:54
【问题描述】:
我已经创建并安装了几次服务。最初它工作正常,但是在服务代码中进行了一些更改后,当我在 Services.msc 中重新启动服务时它开始给出错误:
错误 1053:服务没有及时响应启动或控制请求
代码:
public partial class AutoSMS : ServiceBase
{
public AutoSMS()
{
InitializeComponent();
eventLog1.Clear();
if (!System.Diagnostics.EventLog.SourceExists("MySource"))
{
System.Diagnostics.EventLog.CreateEventSource(
"MySource", "MyNewLog");
}
eventLog1.Source = "MySource";
eventLog1.Log = "MyNewLog";
Timer checkForTime = new Timer(5000);
checkForTime.Elapsed += new ElapsedEventHandler(checkForTime_Elapsed);
checkForTime.Enabled = true;
}
protected override void OnStart(string[] args)
{
eventLog1.WriteEntry("In OnStart");
}
protected override void OnStop()
{
eventLog1.WriteEntry("In onStop.");
}
void checkForTime_Elapsed(object sender, ElapsedEventArgs e)
{
string Time = "15:05:00";
DateTime dateTime = DateTime.ParseExact(Time, "HH:mm:ss",
CultureInfo.InvariantCulture);
if (DateTime.Now == dateTime) ;
eventLog1.WriteEntry(Time);
}
}
这是我的主要方法代码
static void Main()
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new AutoSMS()
};
ServiceBase.Run(ServicesToRun);
}
我也尝试了以下步骤:
- 转到开始 > 运行 > 并键入 regedit
- 导航到:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control
- 选中控制文件夹后,右键单击右侧窗格并 - 选择新的 DWORD 值
- 将新的 DWORD 命名为:ServicesPipeTimeout
- 右键单击 ServicesPipeTimeout,然后单击修改
- 点击十进制,输入“180000”,然后点击确定
- 重启电脑
我曾经使用以下命令安装和卸载它:
installutil AutoSMS.exe
installutil /u AutoSMS.exe
【问题讨论】:
-
Windows 事件日志说明了什么?还是说
Error 1053?这可能是一个权利问题。尝试以Local System用户身份运行服务。 -
将来在 Main() 方法中使用 System.Diagnotstics.Debugger.Launch() 可能会很有用,这样您就可以使用调试器了。
标签: c# .net timer windows-services