hi i am working on c# window services, for that i have set some timer code in onstart method as below code i have pasted it:
protected override void OnStart(string[] args)
{
timerjob.Elapsed += new ElapsedEventHandler(CsvGenFromDatabase);
// ad 2: set interval to 1 minute (= 60,000 milliseconds)
timerjob.Interval = Convert.ToDouble(DueTime);
// ////ad 3: enabling the timer
timerjob.Enabled = true;
}
CsvGenFromDatabase is my method which will so my service, here my problem is i have set a timer (duetime) about 1 min for example if i tested simple volume job means it was performing good, if suppose if i given a huge volume of work for service to do when timer (duetime) was same 1 min at this scenario i m facing some error because still service work does not completed full but time 1 min passed away since service will poll new instance past work was not completed fully, for this scenario how do i handle to my service with out effecting any work when service was in one instance,kindly can any on give suggesions please
In your
CsvGenFromDatabasemethod you could calltimerjob.Stop()before your long running process. Once the process has complete you can calltimerjob.Start()to start the timer again.Example:
I’m assuming
timerjobis available globally.