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. Visual Basic
  4. Using InvokeRequired with a Timer control and a second thread

Using InvokeRequired with a Timer control and a second thread

Scheduled Pinned Locked Moved Visual Basic
helptutorial
3 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.
  • E Offline
    E Offline
    ESTAN
    wrote on last edited by
    #1

    Hello, I am a bit stuck with my timer control. My timer control works in the main thread. Now i have other threads running doing some stuff. This second thread needs to enable the timer. Well the timer.Enabled is indeed true, but i don't get events, it doesn't tick. I read along the web to use the InvokeRequired. Well, i can't figure out how to use it. Can someone please put me on the right track. Thanks in advance.

    L 1 Reply Last reply
    0
    • E ESTAN

      Hello, I am a bit stuck with my timer control. My timer control works in the main thread. Now i have other threads running doing some stuff. This second thread needs to enable the timer. Well the timer.Enabled is indeed true, but i don't get events, it doesn't tick. I read along the web to use the InvokeRequired. Well, i can't figure out how to use it. Can someone please put me on the right track. Thanks in advance.

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

      You need Control.InvokeRequired and Control.Invoke when you want to access a Control from within a thread that did not create the Control (normally the main or "GUI" thread). Most timers run their event in some thread, and hence need Invoke to touch Controls; by design Forms.Timer does not. If you want to know more about it, read up on it in MSDN, some good articles on CP, or Google. There is a simple example (C#) burried inside my Sokoban article. :)

      Luc Pattyn


      try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }


      E 1 Reply Last reply
      0
      • L Luc Pattyn

        You need Control.InvokeRequired and Control.Invoke when you want to access a Control from within a thread that did not create the Control (normally the main or "GUI" thread). Most timers run their event in some thread, and hence need Invoke to touch Controls; by design Forms.Timer does not. If you want to know more about it, read up on it in MSDN, some good articles on CP, or Google. There is a simple example (C#) burried inside my Sokoban article. :)

        Luc Pattyn


        try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }


        E Offline
        E Offline
        ESTAN
        wrote on last edited by
        #3

        Hello, Thanks for your answer. It is indeed quiet simple. I read the following article on MSDN: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbconServerBasedTimers.asp And I replaced my Windows Timer to a Server Timer, problem solved. Thank you. ESTANNY

        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