Several answers suggested sending some messages and then causing a dream until the next message was sent.
How do you sleep in this case, everything is important.
You can - in theory - tell a thread to sleep for several hours, however, if during this time the application (or service) should be turned off, then you have problems. The process will be completed, no cleaning will be performed. This is less than ideal.
Do not confuse the concept of a survey for work and sleep between surveys.
If you need to wait 5 minutes (or 5 hours) until the next database poll, that’s fine, but you’ll never want to * sleep for more than a second or two at a time.
What will i do.,.
Write a Windows service. The service has one active thread that polls the database, see Any messages that should send and sends them. He will then poll the custom delay (1 minute, 5 minutes, 1 hour, what ever fits). However, he will never sleep for more than a second while he waits for a database survey.
If you can be sure that messages can be added only for sending after the last message in the database? If so, you can check the time of the next message and not poll until this time.
However, if I find that the next message does not need to be sent within 5 hours, is it possible that while I wait for the message to be sent in 30 minutes?
If so, you will never be able to trust “Next Message Time” and do not poll until you need to constantly poll your fixed NB interval to say again, your poll interval and your wait interval are not the same thing.
source share