JSHunjan
JSHunjan

Reputation: 397

Scheduler to do some tasks on time

I am working on a scheduler to do certain tasks like send email to users etc. Its a basic one which runs every 5 mins and do its job. I need to make some modifications into that so that it can work on demand. For example, I need to send email to a user at 11:00 AM, to another user at 11:02 AM. How can I make the scheduler to run on time without using a lot of resources on server. I know if I need to send emails every minute, then its sleep time should be one minute or less.

Is there any way to call it on demand or I need to have one thread active all the time to check when to do what and at that time activate scheduler or other process responsible for sending email.

Please suggest. Your inputs will be valuable.

Thanks.

Upvotes: 0

Views: 111

Answers (1)

Brian Shamblen
Brian Shamblen

Reputation: 4703

If you need to send emails every minute it would be better to create a service and have the service poll the database every minute to look for work and sleep for 1 minute in between loops.

If you only need to run your code once an hour it would be better to use the Windows Task Scheduler.

Upvotes: 1

Related Questions