我已经创建并安装了几次服务。起初它工作得很好,但是在服务代码中做了一些修改之后,当我在 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);
}
我还尝试了以下步骤:
我用以下命令安装和卸载它:
installutil AutoSMS.exe
installutil /u AutoSMS.exe