title: 1053 windows service did not respond in timely fashion
body: <p>I have one Web app running in IIS and communicates to a Windows Service through WCF hosted in the same machine. Internally Windows Service executes various job and sometimes it is quite busy with processing User requests. At 1st I had the issue with Start of Service because it some imes take much time to Start &amp; eventually throws the Error i.e. Service Timeout. To fix this I moved the code to another Thread instead of the Main Thread. Everything works fine but now I observed that some times I am getting the error on Service Stop i.e.</p>
  
  <pre><code>**1053 windows service did not respond in timely fashion**
  </code></pre>
  
  <p>My Service OnStop() code:</p>
  
  <pre><code>protected override void OnStop()
          {
              // Stop the WCF service
              if (myServiceHost != null)
              {
                  myServiceHost.Close();
                  myServiceHost = null;
              }
  
              // Stop the scheduler
  
              if (myScheduleManager != null)
              {
                  myScheduleManager.Stop();
              }
  
              // Update the registry value
              Logger.GetInstance().LogEvent(this.GetType().Name, LogLevel.INFO, "Updating registry...");
              Settings.GetInstance().LastStopTime = DateTime.Now.ToString();
  
              Logger.GetInstance().LogEvent(this.GetType().Name, LogLevel.INFO, "Service stopped.");
          }
  </code></pre>
  
  <p>It generally happens when Service is too busy. But finally it stops after 30-40 mins of time. I know this happens due to Time out issue in Windows Service coz the default time is very less &amp; it treats it as Time out.</p>
  
  <p>My question what is the best practice to avoid such bottle necks means shall I move my Stop related tasks under another Thread &amp; do asynchronous call to release resources in that Thread. But what will happen if during release resources, User will Start the Service?</p>