所以我正在尝试运行我编写的服务,由于某种原因,当我尝试启动它时它给了我这个错误:
Error 1053: the service did not respond to the start or control request in a timely fashion
我的代码非常基本。
static void Main(string[] args)
{
try
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new Program()
};
ServiceBase.Run(ServicesToRun);
}
catch (Exception ex)
{
string SourceName = "WindowsService.ExceptionLog";
if (!EventLog.SourceExists(SourceName))
{
EventLog.CreateEventSource(SourceName, "Application");
}
EventLog eventLog = new EventLog();
eventLog.Source = SourceName;
string message = string.Format("Exception: {0} \n\nStack: {1}", ex.Message, ex.StackTrace);
eventLog.WriteEntry(message, EventLogEntryType.Error);
}
}
public Program()
{
this.ServiceName = "FetchFeed";
}
protected override void OnStart(string[] args)
{
base.OnStart(args);
//TODO: place your start code here
repeat: FetchFeed();
Thread.Sleep(3600000);
goto repeat;
}
protected override void OnStop()
{
base.OnStop();
//TODO: clean up any variables and stop any threads
}
private static void FetchFeed()
{
//Some HTTP requests and retrieval.
}
这是安装程序类:
[RunInstaller(true)]
public class Service_Installer : Installer
{
public Service_Installer()
{
ServiceProcessInstaller processInstaller = new ServiceProcessInstaller();
ServiceInstaller serviceInstaller = new ServiceInstaller();
//set the privileges
processInstaller.Account = ServiceAccount.LocalSystem;
serviceInstaller.DisplayName = "FetchFeed";
serviceInstaller.StartType = ServiceStartMode.Manual;
//must be the same as what was set in Program's constructor
serviceInstaller.ServiceName = "FetchFeed";
this.Installers.Add(processInstaller);
this.Installers.Add(serviceInstaller);
}
}
错误背后的原因可能是什么?我已经检查了 FetchFeed() 是否可以作为一个没有异常的独立应用程序工作。