System.Threading.Timer losing time

M

MarketMole

Tribe,

Running the simplest System.Threading.Timer code on Windows 7,
x64 .NET 3.5 and I'm losing time...

5 second intervals - printing to console:

18:40:00.417
18:40:05.425
18:40:10.434
18:40:15.442
18:40:20.442
18:40:25.450
18:40:30.459
18:40:35.467
18:40:40.475
18:40:45.484
18:40:50.492
18:40:55.500

I'm losing about 7 milliseconds every print. HOW CAN THIS BE?

Code to reproduce this:


using System;
using System.Threading;

namespace TimerTest {
public class Program {
static void Main(string[] args) {
TimerTest tt = new TimerTest();
tt.Start();
Console.Read();
}
}

public class TimerTest {

System.Threading.Timer heartbeatTimer;

public virtual void Start() {
if (this.heartbeatTimer != null)
return;
StartHeartbeatTimer();
}

protected virtual void StartHeartbeatTimer() {
heartbeatTimer = new Timer(new
TimerCallback(DoHeartbeatNotification), null, 0, 5000);
}

public void DoHeartbeatNotification(object state) {
DateTime systemTimestamp = DateTime.Now;
Console.WriteLine(string.Format("{0:HH:mm:ss.fff}",
systemTimestamp));
}
}
}

///~~~~~~~~~~~~~~

I mean, this should not be. Has anyone else see this issue?

Thanks,
Dave Cline

~ Leximize your word! ~
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top