Reputation: 663
I have an Azure Worker Role with n (currently n = 2) instances. Each of these instances has a System.Timers.Timer on its main thread that executes every 20 seconds, spawning some work processes. When the role instances boot up initially, they synchronize themselves via internal endpoints so that the timers start at the same time (this works).
Over the course of even a day, these two timers with the same interval tend to wander - one will end up starting several seconds before it used to, and the other may go the same direction or, worse, the other.
My run method is basically the following:
public override void Run()
{
while (true)
{
GC.KeepAlive(this.LogTimer); // make sure garbage collection never touches the timer
}
}
Questions:
Thanks in advance for your time,
Alex
Upvotes: 0
Views: 777
Reputation: 164331
A System.Timers.Timer is not 100% accurate, it is limited by the thread scheduling in the OS. It makes good sense that two separate servers each running a Timer, eventually will get out of synch.
Upvotes: 2