Timing Error when using System.Timers.Timer
-
I have the following code in WinForm which kick off a periodic timed event every 10 millisecs. The event updates a count every 100 event calls. I expect the display to be updated every 10ms * 100 = 1 sec. The actual value displayed in the label after 60 seconds is 3600. i.e. 60 event elapses every second. By changing tmrTimersTimer.Interval it has no effect on the count i.e. it is still 3600. What am I doing wrong?
private void evtLoad(object sender, System.EventArgs e) { tmrTimersTimer = new System.Timers.Timer(10.0); tmrTimersTimer.Elapsed += new ElapsedEventHandler(tmrTimersTimer_Elapsed); tmrTimersTimer.SynchronizingObject = this; //Synchronize with the current form... tmrTimersTimer.AutoReset = true; tmrTimersTimer.Enabled = true; tmrTimersTimer.Start(); } private void tmrTimersTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { if (++Count % 100 == 0) { lblCount.Text = Count.ToString(); } }
-
I have the following code in WinForm which kick off a periodic timed event every 10 millisecs. The event updates a count every 100 event calls. I expect the display to be updated every 10ms * 100 = 1 sec. The actual value displayed in the label after 60 seconds is 3600. i.e. 60 event elapses every second. By changing tmrTimersTimer.Interval it has no effect on the count i.e. it is still 3600. What am I doing wrong?
private void evtLoad(object sender, System.EventArgs e) { tmrTimersTimer = new System.Timers.Timer(10.0); tmrTimersTimer.Elapsed += new ElapsedEventHandler(tmrTimersTimer_Elapsed); tmrTimersTimer.SynchronizingObject = this; //Synchronize with the current form... tmrTimersTimer.AutoReset = true; tmrTimersTimer.Enabled = true; tmrTimersTimer.Start(); } private void tmrTimersTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { if (++Count % 100 == 0) { lblCount.Text = Count.ToString(); } }
IIRC, the max resolution of the timer is 54 ms. Regards Senthil _____________________________ My Blog | My Articles | WinMacro
-
IIRC, the max resolution of the timer is 54 ms. Regards Senthil _____________________________ My Blog | My Articles | WinMacro
Is the 54ms documented anywhere? Does anyone have any recommendation how I can get a resolution of 5ms? I am updating the display with real-time data every 5ms. I have used other timers but this causes the display to to be updated in an irregular manner. It is as thought that the timer is not executing at the correct time. Thanks, Liam
-
Is the 54ms documented anywhere? Does anyone have any recommendation how I can get a resolution of 5ms? I am updating the display with real-time data every 5ms. I have used other timers but this causes the display to to be updated in an irregular manner. It is as thought that the timer is not executing at the correct time. Thanks, Liam
I was wrong, the 54ms resolution is for the Windows Forms Timer. This[^] says the max resolution is 10 ms. Regards Senthil _____________________________ My Blog | My Articles | WinMacro