title: service status showing as starting why is not started when by using c#.net
body: <p>here i am using window service, using a logic as my service will work only once in the 24 hours by with the help of have configured in the app.config.</p>
  
  <p>Ex : i will mention hour in app config as "10" so daily once my service will run by exactly 10 clock</p>
  
  <p>But problem is when i start my service, it was throwing an error as 1053(Timely fashion error) and status it was showing as Starting in services.msc, no more start and Restart functions are not shown in the popup window of right click</p>
  
  <p>wondering is it was done the job perfectly,by ten o clock exactly.</p>
  
  <p>why it was not shown as started, why it was throwing an error?</p>
  
  <p>i have pasted the sample code bellow and kindly advice whether if i did any wrong</p>
  
  <p>on start method</p>
  
  <pre><code>protected override void OnStart(string[] args)
  {
       DateTime tenAM = DateTime.Today.AddHours(strSETHOST);
  
  
       if (DateTime.Now &gt; tenAM)
            tenAM = tenAM.AddDays(1);
  
  
       // calculate milliseconds until the next 10:00 AM.  
       int timeToFirstExecution = (int)tenAM.Subtract(DateTime.Now).TotalMilliseconds;
  
       // calculate the number of milliseconds in 24 hours.   
       int timeBetweenCalls = (int)new TimeSpan(24, 0, 0).TotalMilliseconds;
  
       TimerCallback methodToExecute = kickstart;
  
       // start the timer.  The timer will execute "ProcessFile" when the number of seconds between now and   
       // the next 10:00 AM elapse.  After that, it will execute every 24 hours.   
       System.Threading.Timer timer = new System.Threading.Timer(methodToExecute, null, timeToFirstExecution, timeBetweenCalls);
  
       Thread.Sleep(Timeout.Infinite);
  
   }
  
   protected override void OnStop()
   {
   }
  
   public static void kickstart(object nowtime)
   {
  
        Service1  foo = new Service1();
        foo.Startjob();
   }
  
   private void Startjob()
   {
        using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew)) // Transaction Scope Started
        {
             if ((threadPURGE == null) || (threadPURGE.ThreadState == System.Threading.ThreadState.Stopped) || (threadPURGE.ThreadState == System.Threading.ThreadState.Unstarted) || (threadPURGE.ThreadState == System.Threading.ThreadState.Aborted))
             {
                  threadPURGE = new Thread(new ThreadStart(DynamicThreadGen));  // Thread Initialize for ITD 
             }
  
             try
             {
                  if ((threadPURGE == null) || (threadPURGE.ThreadState == System.Threading.ThreadState.Stopped) || (threadPURGE.ThreadState == System.Threading.ThreadState.Unstarted) || (threadPURGE.ThreadState == System.Threading.ThreadState.Aborted))
                  {
                       threadPURGE.Start();  // Thread Started for ITD 
                  }
  
  
             }
             catch (Exception ex)
             {
                  string err = ex.Message.ToString();
             }
             finally
             {
                  scope.Complete();
             }
        }
  
   }
  
   private void DynamicThreadGen()
   {
       /// service work 
   }
  </code></pre>