我目前正在遇到一个问题,我写的Windows服务在启动时会立即“超时”。我得到的消息是Error 1053: The service did not respond to the start or control request in a timely fashion.
我检查了事件查看器,我看到了该消息和另一个A timeout was reached (30000 milliseconds) while waiting for the X service to connect.
唯一的问题是它没有等待30秒超时,它更像是半秒。
我的服务是OnStart()
private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private string version = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion;
private string incomingProdFileLocation = ConfigurationManager.AppSettings["ProdIncomingFileLocation"];
private string incomingCertFileLocation = ConfigurationManager.AppSettings["CertIncomingFileLocation"];
//private string incomingCombFileLocation = ConfigurationManager.AppSettings["CombIncomingFileLocation"];
private string processedFileLocation = ConfigurationManager.AppSettings["ProcessedFileLocation"];
private string errorFileLocation = ConfigurationManager.AppSettings["ErrorFileLocation"];
FileSystemWatcher prodWatcher = new FileSystemWatcher();
FileSystemWatcher certWatcher = new FileSystemWatcher();
//FileSystemWatcher combWatcher = new FileSystemWatcher();
protected override void OnStart(string[] args) {
log.InfoFormat("Starting up Merchant Bulk Load Service v{0}", version);
if (verifyDirectories()) {
log.InfoFormat("Initialize Prod FileSystemWatcher() at {0}", incomingProdFileLocation);
prodWatcher.Path = incomingProdFileLocation;
prodWatcher.Filter = "*.csv";
prodWatcher.Created += ProdBulkLoadFileReceived;
prodWatcher.EnableRaisingEvents = true;
log.InfoFormat("Initialize Cert FileSystemWatcher() at {0}", incomingCertFileLocation);
certWatcher.Path = incomingCertFileLocation;
certWatcher.Filter = "*.csv";
certWatcher.Created += CertBulkLoadFileReceived;
certWatcher.EnableRaisingEvents = true;
/*log.InfoFormat("Initialize Comb FileSystemWatcher() at {0}", incomingCombFileLocation);
combWatcher.Path = incomingCombFileLocation;
combWatcher.Filter = "*.csv";
combWatcher.Created += CombBulkLoadFileReceived;
combWatcher.EnableRaisingEvents = true;*/
} else {
log.ErrorFormat("verifyDirectories() returned false. Service stopping");
this.Stop();
}
}
private bool verifyDirectories() {
// verify each of the necessary directories exists before setting up any FileSystemWatcher()s
if (!Directory.Exists(incomingProdFileLocation)) {
log.ErrorFormat("Incoming production file location {0} does not exist. Please create the directory or edit the configuration file.",
incomingProdFileLocation);
return false;
}
if (!Directory.Exists(incomingCertFileLocation)) {
log.ErrorFormat("Incoming cert file location {0} does not exist. Please create the directory or edit the configuration file.",
incomingCertFileLocation);
return false;
}
/*if (!Directory.Exists(incomingCombFileLocation)) {
log.ErrorFormat("Incoming combined file location {0} does not exist. Please create the directory or edit the configuration file.",
incomingCombFileLocation);
return false;
}*/
if (!Directory.Exists(processedFileLocation)) {
log.ErrorFormat("Processed file location {0} does not exist. Please create the directory or edit the configuration file.",
processedFileLocation);
return false;
}
if (!Directory.Exists(errorFileLocation)) {
log.ErrorFormat("Error file location {0} does not exist. Please create the directory or edit the configuration file.",
errorFileLocation);
return false;
}
return true;
}
我的整个服务在我们的开发和认证环境中运行良好,但不会在我们的生产环境中启动,它似乎甚至没有进入OnStart(),因为永远不会生成日志。我检查过的事情:
此刻我很茫然;任何帮助都会很棒。
修改 再次仔细检查.NET框架后,我意识到我检查了错误的服务器版本。一个好的方法是双击服务的实际exe文件并查看它的内容。在我的情况下,它字面上说“确保安装4.0”,这促使我再次检查,在那里我看到4.0没有安装。
答案 0 :(得分:3)
您确定.net是最新的吗?如果例如3.5在机器上并且您使用的是4.0,则可能发生这种情况。
答案 1 :(得分:0)
这是一张旧票,但是我在应用程序中创建的所有Windows服务(大约有10个)上都看到了相同的错误(尽管是“ 90000毫秒”而不是30000)。 .net框架已安装且正常运行。
我检查了设置此90000 ms(90秒)限制的注册表设置。 在节点中, HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control ServicesPipeTimeout 的值为90000(十进制)。
我不需要将其设置为90000,也不知道为什么要设置为90000,但是它肯定不是在等待90秒,而是立即失败。
所以我将值修改为30000并重新启动了服务器。
所有服务开始成功启动或重新启动。