work the service based upon datetime parameteric caluclations by using c# window service
===

here i below pasted code i m using in current window service solution,this will run job every day 10 AM regularly, i will pass the parameters using App.configuaration file 

APP.CONFIG

    <add key ="FIREHOST_TIME" value ="10" ></add>
    <add key ="SETDAYS" value ="1" ></add>


CODE BEHIND PAGE

    protected override void OnStart(string[] args)
        {
    
         DateTime tenAM = DateTime.Today.AddHours(FIREHOST_TIME);
    
    
    
                if (DateTime.Now > tenAM)
                    tenAM = tenAM.AddDays(SETDAYS);
    
    
                // 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);
    
    
             }

Now I am trying to run my service, based up on the below Mentioned conditions:

 i want to start my service but it should job perform the job based on the this new tag which i will add newly in app.config

<add key ="RUN_NOW" value ="1" ></add>  <!-- 0 = NO, 1 = Yes -->
<add key ="WAIT_DAYS" value ="5" ></add>




    BY based on above four tags
    
    if RUN_NOW == 1
    
          has to perform service based on FIREHOST_TIME and SETDAYS normal thing
    else 
    
        service have to perform the Job doing by after 5 days(because WAIT_DAYS = 5) 
         then it have to use the FIREHOST_TIME and SETDAYS value




Note: service should not get stop, it should be in started condition only

How can i achieve this?


  








