0
protected override void OnStart(string[] args)
    {
        timer();
    }
    public void Timer_Elap(object source, ElapsedEventArgs e)
    {

        //Insert Into DataBase

    }
    protected override void OnStop()
    {

    }
    protected void timer()
    {

        aTimer = null;
        aTimer = new System.Timers.Timer();
        aTimer = new Timer(10000);
        aTimer.Elapsed += new ElapsedEventHandler(this.Timer_Elap);
        aTimer.Interval = 5000;
        aTimer.AutoReset = true;
        aTimer.Enabled = true;
    }

Context : I have used the above code to do the Insert process for every 5 seconds.But After 30 min the timer stop firings the insert method. And then, After 30 mins the timer restart automatically once again. How to reduce the timer start/stop timing and need to run the timer for 24 hours for every 5 seconds without any start/stop of the timer

Means: the values getting inserted for every 5 seconds up-to 30 min and stops inserting,then after 30 min of gap it starts inserting again automatically.. i don't want that 30 min gap

  • This link might help you? : https://www.aspsnippets.com/Articles/Repeat-Task-every-N-interval-using-Windows-Service-in-C-and-VBNet.aspx – xoxo Oct 04 '18 at 05:24
  • Take a look at https://web.archive.org/web/20150329101415/https://msdn.microsoft.com/en-us/magazine/cc164015.aspx – Oliver Oct 04 '18 at 05:42
  • Possible duplicate of [Calling a method every x minutes](https://stackoverflow.com/questions/13019433/calling-a-method-every-x-minutes) – Ziaul Kabir Fahad Oct 04 '18 at 05:42
  • The code you've shown won't pause for 30 minutes. Whatever the cause of these pauses (and whether they're actually the timer being disabled or a failure of whatever code runs in `Timer_Elap`) aren't going to be visible to anybody else based on the code shown here. You need to do more debugging. – Damien_The_Unbeliever Oct 04 '18 at 06:54
  • @ Damien_The_Unbeliever: No the code is working good , don't know what is the reason for the interval, Am using this in Windows service. – Renganathan Rennie Oct 04 '18 at 07:00
  • What I'm saying is that, *from just the code you've posted*, nobody else is going to be able to tell you where the pause is coming from either. – Damien_The_Unbeliever Oct 04 '18 at 07:26
  • Then give me example which need to insert process for every 5 seconds without interval – Renganathan Rennie Oct 04 '18 at 09:05
  • @ Kamala HB .. it works thanks And also thanks to all who helped me with your suggestions – Renganathan Rennie Oct 09 '18 at 06:32

0 Answers0