C# Windows服务“;超时“;启动时立即

C# Windows服务“;超时“;启动时立即,c#,windows-services,C#,Windows Services,我现在遇到了一个问题,我写的一个Windows服务在启动时立即“超时”。我收到的消息是错误1053:服务没有及时响应启动或控制请求。我检查了事件查看器,看到该消息,在等待X服务连接时,另一个超时(30000毫秒)。唯一的问题是它没有等待30秒超时,更像是半秒钟 我的服务是OnStart() 我的整个服务在我们的开发和认证环境中工作得非常出色,但不会在我们的生产环境中启动,因为它似乎连OnStart()都没有,因为从来没有创建过日志。我检查过的东西: 确保服务在必要的目录中有正确的权限,它会这样做

我现在遇到了一个问题,我写的一个Windows服务在启动时立即“超时”。我收到的消息是
错误1053:服务没有及时响应启动或控制请求。
我检查了事件查看器,看到该消息,在等待X服务连接时,另一个
超时(30000毫秒)。
唯一的问题是它没有等待30秒超时,更像是半秒钟

我的服务是OnStart()

我的整个服务在我们的开发和认证环境中工作得非常出色,但不会在我们的生产环境中启动,因为它似乎连OnStart()都没有,因为从来没有创建过日志。我检查过的东西:

  • 确保服务在必要的目录中有正确的权限,它会这样做
  • 确保安装了我的服务所针对的.NET framework的正确版本(4),它是
  • 确保事件查看器没有抛出任何其他类型的错误,这些错误可能会提示正在发生的事情,没有任何错误
  • FileSystemWatcher的所有目录实际上都存在,它们确实存在
  • log4net文件的目录存在,它确实存在
  • 我现在不知所措;任何帮助都会很棒

    编辑
    在再次仔细检查.NET framework之后,我意识到我检查了错误的服务器版本。确定的一个好方法是双击服务的实际exe文件,看看它说了什么。在我的例子中,它的字面意思是“确保安装了4.0”,这促使我再次检查,在那里我看到4.0没有安装。

    你确定你的.net是最新的吗。例如,如果计算机上安装了3.5,而您使用的是4.0,则可能会发生这种情况。

    这是一个旧问题,但我只是在我们作为应用程序的一部分创建的所有Windows服务上看到了相同的错误(虽然是“90000毫秒”而不是30000毫秒)(大约10毫秒)。Net framework已安装并正常运行

    我检查了设置90000毫秒(90秒)限制的注册表设置。 在节点中,HKEY\U LOCAL\U MACHINE\SYSTEM\CurrentControlSet\Control ServicesPipeTimeout的值为90000(十进制)

    我不需要它是90000,我也不知道为什么它被设置成这样,但它肯定没有等待90秒——它马上就失败了

    因此,我将值修改为30000并重新启动了服务器


    所有服务都成功开始启动或重新启动。

    我通常将try-catch块放入OnStart,并将log放入catch块以获取更多信息。这是我的错误,当我检查.NET framework时,我无意中看到了在生产环境中登录的其他服务器之一。仔细检查后,它实际上在3.5停止,我现在就开始关闭它。。。
        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;
        }