Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Timing Error when using System.Timers.Timer

Timing Error when using System.Timers.Timer

Scheduled Pinned Locked Moved C#
helpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LiamD
    wrote on last edited by
    #1

    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(); } }

    S 1 Reply Last reply
    0
    • L LiamD

      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(); } }

      S Offline
      S Offline
      S Senthil Kumar
      wrote on last edited by
      #2

      IIRC, the max resolution of the timer is 54 ms. Regards Senthil _____________________________ My Blog | My Articles | WinMacro

      L 1 Reply Last reply
      0
      • S S Senthil Kumar

        IIRC, the max resolution of the timer is 54 ms. Regards Senthil _____________________________ My Blog | My Articles | WinMacro

        L Offline
        L Offline
        LiamD
        wrote on last edited by
        #3

        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

        S 1 Reply Last reply
        0
        • L LiamD

          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

          S Offline
          S Offline
          S Senthil Kumar
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups