Of course you can check it out. All you need is
- start the service
- note that it calls the expected call after 5 minutes.
- (note that it calls the expected call every 5 minutes a couple more times)
You can check this manually or (preferably) create / use an automatic test harness that allows you to check repeatedly and reliably, as many times as you want. This is possible even with a simple batch file.
To find that the timer is working correctly, you can check its log file. Of course, this also helps if you create a method of the called class, rather than hardcoding. That way, you can run your automated tests using a dummy working class that doesn't flood your inbox :-)
To make it even more verifiable, you can also extract the synchronization logic from your service class so that it can be run from a regular application. Then you can test it even easier, even using a unit test framework like NUnit. This allows for more rigorous testing using different time intervals, etc. And the service class itself becomes an almost empty shell, whose only task is to start and call other classes. If you have verified that all classes containing real program logic (i.e., all code that may fail) will be checked by one and will work perfectly, you can have a lot more confidence that your entire application, when it is integrated from its small parts, it works correctly.
Update
Looking through your code, it seems that you are not initializing flag
anywhere, so its default value will be false
. You must initialize it to true
in the constructor, otherwise your email retriever will never be called, even if the timer fires properly.
To set the interval to 1 minute, I would prefer
scheduleTimer1.Interval = 1 * 60 * 1000;
source share