Polling Cycles
I'm setting up a system whereby a service is polling a database looking for information. What I'm attempting to do is set up a polling cycle so that the webservice won't be hitting the database every 30 seconds. For this cycle, after the service has started up I want it to poll the database at the 1 minute mark, if nothing is found, then it should poll the database 2 minutes later. This doubling of the time between polls should continue until the 1 hour mark is reached at which time it would reset to 1 minute.
What would be the best way to accomplish this task?
Laurence -
[614 byte] By [
Hunterlmc] at [2007-11-11 7:36:36]

# 5 Re: Polling Cycles
You don't have to use a Timer control, just use the Timer class. The following should help:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemthreadingtimerclasstopic.asp
With respect to Thread.Sleep, in order to use it you would probably have to spawn a worker thread to handle your polling code. If you don't use a worker thread then your service will not likely respond to stop and start events. I haven't checked the below code, but it may contain a solution to what I'm referring to:
http://blogs.snapsis.com/PermaLink,guid,5b99a8aa-3516-4a45-84d2-4707b08cba86.aspx