You could do it with a Timer, but you would need to have some form of locking on your database scan and update. A simple lock
to synchronize may be enough to prevent multiple runs from occurring.
That being said, it might be better to start a timer AFTER you're operation is complete, and just use it one time, then stop it. Restart it after your next operation. This would give you 30 seconds (or N seconds) between events, with no chance of overlaps, and no locking.
Example :
System.Threading.Timer timer = null;
timer = new System.Threading.Timer((g) =>
{
Console.WriteLine(1); //do whatever
timer.Change(5000, Timeout.Infinite);
}, null, 0, Timeout.Infinite);
Work immediately .....Finish...wait 5 sec....Work immediately .....Finish...wait 5 sec....
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…