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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Isuses with timers + fast intervals

Isuses with timers + fast intervals

Scheduled Pinned Locked Moved C#
questionwinforms
9 Posts 6 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.
  • B Offline
    B Offline
    bankai123
    wrote on last edited by
    #1

    Hi, I have a question about the Windows Forms Timer class. Suppose that the timer's interval is set at say 10ms and the work it does in each tick takes longer than 10ms to complete. Is each tick executed on a separate thread? If not, then what happens?

    K S M C S 6 Replies Last reply
    0
    • B bankai123

      Hi, I have a question about the Windows Forms Timer class. Suppose that the timer's interval is set at say 10ms and the work it does in each tick takes longer than 10ms to complete. Is each tick executed on a separate thread? If not, then what happens?

      K Offline
      K Offline
      kselman
      wrote on last edited by
      #2

      Im guessing the next Tick will be delayed. Good question.. You can experiment with two timers and two counters .. the one with the lower count would be the delayed function.

      1 Reply Last reply
      0
      • B bankai123

        Hi, I have a question about the Windows Forms Timer class. Suppose that the timer's interval is set at say 10ms and the work it does in each tick takes longer than 10ms to complete. Is each tick executed on a separate thread? If not, then what happens?

        S Offline
        S Offline
        Stathread
        wrote on last edited by
        #3

        no, executes again.

        B 1 Reply Last reply
        0
        • S Stathread

          no, executes again.

          B Offline
          B Offline
          bankai123
          wrote on last edited by
          #4

          So the tick executes again if it cannot complete it's work before the next tick is called?

          1 Reply Last reply
          0
          • B bankai123

            Hi, I have a question about the Windows Forms Timer class. Suppose that the timer's interval is set at say 10ms and the work it does in each tick takes longer than 10ms to complete. Is each tick executed on a separate thread? If not, then what happens?

            M Offline
            M Offline
            Martin 0
            wrote on last edited by
            #5

            Hello, Here I found a very interesting post at this forum about this question. http://www.codeproject.com/script/comments/forums.asp?msg=1643202&forumid=1649&XtraIDs=1649&searchkw=Timer.Tick&sd=9+Jan+2006&ed=7+Nov+2006&stype=1#xx1643202xx[^] Hope this helps you. All the best, Martin

            1 Reply Last reply
            0
            • B bankai123

              Hi, I have a question about the Windows Forms Timer class. Suppose that the timer's interval is set at say 10ms and the work it does in each tick takes longer than 10ms to complete. Is each tick executed on a separate thread? If not, then what happens?

              C Offline
              C Offline
              Coding C
              wrote on last edited by
              #6

              Hi, the timer event occurs after 10ms even if the first execution of event is yet to complete. what u can do to cope this prob is set the timer enabled=false once its event execution starts so event doesnt fire again even if 10ms is over. and when ur code execution is complete u can set enabled=true again. Something like this timer1_Tick() { timer1.enabled=false //do ur work here timer1.enabled=true } hope this works... Nitin...

              1 Reply Last reply
              0
              • B bankai123

                Hi, I have a question about the Windows Forms Timer class. Suppose that the timer's interval is set at say 10ms and the work it does in each tick takes longer than 10ms to complete. Is each tick executed on a separate thread? If not, then what happens?

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

                bankai123 wrote:

                Is each tick executed on a separate thread?

                No, all ticks on a System.Windows.Forms.Timer run on the UI thread.

                bankai123 wrote:

                If not, then what happens?

                Every timer tick runs as a result of a WM_TIMER message being processed by the message dispatcher. Windows doesn't post the WM_TIMER message to the message queue if they are any pending messages (including WM_TIMER) in the queue. This prevents the scenario you described (a tick firing even when processing for the previous tick is executing). Note that any message in the message queue will prevent the timer from ticking, so for example, if your UI button click handler takes one second to execute, then you won't get timer ticks for that one second. Also, note that no queuing of ticks happens, so you won't get ticks one after the other corresponding to the period when no timer ticks executed. In the above example, you won't get timer ticks corresponding to that one second period even after your button handler has completed execution. Hope this helps.

                Regards Senthil [MVP - Visual C#] _____________________________ My Blog | My Articles | My Flickr | WinMacro

                1 Reply Last reply
                0
                • B bankai123

                  Hi, I have a question about the Windows Forms Timer class. Suppose that the timer's interval is set at say 10ms and the work it does in each tick takes longer than 10ms to complete. Is each tick executed on a separate thread? If not, then what happens?

                  M Offline
                  M Offline
                  Martin 0
                  wrote on last edited by
                  #8

                  Hello again,

                  bankai123 wrote:

                  Is each tick executed on a separate thread?

                  No, but I think "System.Timers.Timer" does. There you have to use the "Elapsed" event. All the best, Martin

                  B 1 Reply Last reply
                  0
                  • M Martin 0

                    Hello again,

                    bankai123 wrote:

                    Is each tick executed on a separate thread?

                    No, but I think "System.Timers.Timer" does. There you have to use the "Elapsed" event. All the best, Martin

                    B Offline
                    B Offline
                    bankai123
                    wrote on last edited by
                    #9

                    Thanks for all the info, it has been helpful. I've decided to use the System.Timers.Timer class instead, with a interval of 20ms for processing some information. I tried disabling the timer once i entered the event handler and re-enabling it after all the work is done. ( to avoid re-entrance) However it didn't seem to work for me, It seemed to call the first elapsed event once, and doesn't seem to occur again. I gotta debug more, not really sure where the problem lies at the moment.

                    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