0

I have a console application that checks a mail server using the pop protocol, processes any emails it finds, and terminates.

I plan to schedule it using the Task Scheduler. The problem is that I can only schedule it to run every minute (or longer)but nothing less.

Speed is a critical factor for this application, and so I'm hoping I can schedule it so its always checking for emails. I'm wondering what the best approach for this would be.

Is an infinite loop the only way?

I thought of making it a windows service, but wouldn't that also need an infinite loop?

Thanks

Gerson
  • 429
  • 2
  • 16
  • similar to http://stackoverflow.com/questions/2032808/how-to-have-a-loop-in-a-windows-service-without-using-the-timer/2033431#2033431 – John Sobolewski Dec 18 '14 at 00:25
  • I also recommend you check out topshelf. – John Sobolewski Dec 18 '14 at 00:27
  • I am suggesting you run it as a service but using the technique in my first comment you could run it as a scheduled task once a minute and only start a new one if it isn't running and just have it run infinitely and the scheduled task would just restart it if it died. At that point you might as well run it as a service. – John Sobolewski Dec 18 '14 at 00:28
  • Try looking into windows service + timer. The timer should let you go less than a minute. – Andy Refuerzo Dec 18 '14 at 00:28
  • Use windows service. rather than a timer (which gave me a lot of troubles) I will use Thread.sleep() after every loop. This serves as timer and does not consume any processing time when asleep. – Justjyde Dec 18 '14 at 00:38

1 Answers1

0

Two possibilities, but each depend on what your requirements are.

First off, if you want continuous monitoring, why does the application need to terminate? Could your application pause, or loop and drive the updates itself? Why would this inifinite loop be a bad design choice, if that's what you want?

Second possibility, can this client be driven from a Linux or Unix host of some sort, rather than from Windows? *nix operating systems have the "cron" functionality, which provides recurring tasks down to the single second resolution.

If Unix is out, and you don't want to write your own infinite loop, you will want to look for some sort of scheduler program other than Task Scheduler, which provides you more fine grain control on the timing.

JesseM
  • 191
  • 4
  • 7