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. Does the timer event run in a new thread?

Does the timer event run in a new thread?

Scheduled Pinned Locked Moved C#
question
8 Posts 6 Posters 2 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.
  • Y Offline
    Y Offline
    yu jian
    wrote on last edited by
    #1

    If I let a MessageBox to show in the timer event , it will show several messageBoxs, so I think that every one timer event in a new thread, right? How the timer run?

    D L S 3 Replies Last reply
    0
    • Y yu jian

      If I let a MessageBox to show in the timer event , it will show several messageBoxs, so I think that every one timer event in a new thread, right? How the timer run?

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      That depends on which Timer you're using. You can find them in multiple namespaces, like System.Windows.Forms, System.Timers, System.Threading, ... Which one are you using?

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak

      Y 1 Reply Last reply
      0
      • D Dave Kreskowiak

        That depends on which Timer you're using. You can find them in multiple namespaces, like System.Windows.Forms, System.Timers, System.Threading, ... Which one are you using?

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak

        Y Offline
        Y Offline
        yu jian
        wrote on last edited by
        #3

        I donot know the differences between these four timers, I often use the timer in the namespace System.window.forms

        D I D 3 Replies Last reply
        0
        • Y yu jian

          I donot know the differences between these four timers, I often use the timer in the namespace System.window.forms

          D Offline
          D Offline
          daniel ingalla
          wrote on last edited by
          #4

          Your question is difficult to understand- are you asking how you should implement a timer that will show a message box? Windows forms timer events are called on the UI thread via the message pump. The Threading timers are not.

          1 Reply Last reply
          0
          • Y yu jian

            I donot know the differences between these four timers, I often use the timer in the namespace System.window.forms

            I Offline
            I Offline
            Ian Shlasko
            wrote on last edited by
            #5

            They're all different... http://msdn.microsoft.com/en-us/magazine/cc164015.aspx[^] System.Windows.Forms.Timer = Runs in your UI thread, and is part of the message loop. If your GUI is running slowly, this timer will become inaccurate. If you run a long loop on the GUI thread that blocks user input, it'll block this too. Not only will it be inaccurate, but if it falls behind, it will actually just skip any ticks it missed. System.Timers.Timer = Runs in its own thread, and triggers events on a background thread. You can use its Synchronizing object to put its events on the GUI thread if you want, and that'll make it work basically just like the S.W.F.Timer, except that it won't skip ticks. System.Threading.Timer = Similar to the System.Timers.Timer, but gives you finer control and is a little more complicated to use.

            Proud to have finally moved to the A-Ark. Which one are you in?
            Author of the Guardians Saga (Sci-Fi/Fantasy novels)

            1 Reply Last reply
            0
            • Y yu jian

              I donot know the differences between these four timers, I often use the timer in the namespace System.window.forms

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              The System.Windows.Forms.Timer control does not use a seperate thread to raise it's events. It's always going to use the application message pump to raise the event on the UI thread. Since it's using the message pump, the time that you actually see the event fired won't be entirely accurate. The other timers use a seperate thread to call back your code, though the implementations of what you get back and how the timers behave vary slightly.

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak

              1 Reply Last reply
              0
              • Y yu jian

                If I let a MessageBox to show in the timer event , it will show several messageBoxs, so I think that every one timer event in a new thread, right? How the timer run?

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #7

                you may want to read this little article[^]. :)

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                1 Reply Last reply
                0
                • Y yu jian

                  If I let a MessageBox to show in the timer event , it will show several messageBoxs, so I think that every one timer event in a new thread, right? How the timer run?

                  S Offline
                  S Offline
                  Samuel Cherinet
                  wrote on last edited by
                  #8

                  hmm... the timer event is triggered with the interval you specified. So as long as you don't disable it after the first event it will keep on executing the code. got nothing to do with threads

                  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