Timer - run at set time

Asked

Viewed 932 times

1

I am developing a Windows Service, where every day at 18:00 hours, I need an event to be triggered.

So I’m using the class Timer. I managed to trigger an event by defining the property Interval, that is, every 120 seconds, for example, and triggered the event.

However, how do I trigger the event at 18:00 hours?

Follow my code:

 protected override void OnStart(string[] args)
    {
        Timer timer = new Timer();
        timer.Interval = (1000)*(12); // 120  seconds 2 minutos
        timer.Elapsed += new ElapsedEventHandler(this.OnTimer);
        timer.Enabled = true;
        timer.Start();

        Enviar_Email.send_email_Start();
    }

Event to be fired:

 public void OnTimer(object sender, System.Timers.ElapsedEventArgs args)
    {
        Send_Mail();
    }
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.