title: Windows Service "Timeout" instantly on startup
body: <p>I'm currently running in to an issue where a Windows Service I wrote is "timing out" instantly on start up. The message I get is <code>Error 1053: The service did not respond to the start or control request in a timely fashion.</code> I checked Event Viewer and I see that message and another <code>A timeout was reached (30000 milliseconds) while waiting for the X service to connect.</code> Only problem is that it's not waiting 30 seconds to time out, it's more like half a second.</p>
  
  <p>My service's OnStart()</p>
  
  <pre><code>    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;
      }
  </code></pre>
  
  <p>My entire service works splendidly in our development and certification environments, but won't start in our production environment, it doesn't seem like it's even getting to the OnStart() because a log is never made. Things I've checked:</p>
  
  <ol>
  <li>Made sure service had correct permissions in the necessary directories, it does</li>
  <li>Made sure the correct version of .NET framework that my service is targeting (4) is installed, it is</li>
  <li>Made sure Event Viewer wasn't throwing any other types of errors that might give me a hint to what's happening, there's nothing</li>
  <li>All of the directories for the FileSystemWatcher actually exist, they do</li>
  <li>The directory for the log4net file exists, it does</li>
  </ol>
  
  <p>I'm at a loss at the moment; any help would be awesome.</p>
  
  <p><strong>edit</strong>
  After double checking the .NET framework again I realize I checked the wrong server for the versions. A good way to be certain is to double-click on the actual exe file for the service and see what it says. In my case it literally said "Make sure 4.0 is installed" which prompted me to check again and there I saw that 4.0 wasn't installed.</p>