Timer - run at defined time [duplicate]

1

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

So I'm using the Timer class. I was able to trigger an event by setting the Interval property, that is, every 120 seconds, for example, and triggered the event.

But how do I trigger the event at 6:00 p.m?

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 trigger:

 public void OnTimer(object sender, System.Timers.ElapsedEventArgs args)
    {
        Send_Mail();
    }
    
asked by anonymous 22.04.2017 / 23:19

0 answers