简体   繁体   中英

Can we have 2 timers in Window Services?

In a window service, can we have 2 timers, where one runs every 24 hours and other every 30 seconds???

The one that runs every 24 hours does one function and other sends an email every 30 seconds????

thanks!!

Yes, this is possible.

There is no issue in having more than one timer.

Note: testing this on your own would have been faster than asking the question and waiting for an answer here.

You can have so many timers as you want. But also you can have one timer with 30 seconds period:

private int ticks = 0;

private void timerTick(...)
{
    if (2880 == ticks)
    {
        one_void();
        ticks = 0;
    }

    send_email();

    ticks++;
}

That is possible, use two Timer objects from the System.Timers namespace.

You can define the interval time in milliseconds and at the interval eventhandler you can define a method to execute

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM