Announcement

Collapse
No announcement yet.

timer in thread (ie createwaitabletimer for 9.x)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • timer in thread (ie createwaitabletimer for 9.x)

    Hi people,

    How does one create a timer in a thread that does not have
    a dialog? pretty much like CreatWaitableTimer under NT.
    Cant use sleep cos I am using waitForMultipleObjects and waiting
    for a button click aswell as a timer. I can create a timer in
    the main thread and set an event to triger the waitfor when the
    timer fires, but the thread cant reset the timer in the
    main thread when its done ?

    Any ideas ?

    TA.

    NJH.




    ------------------

  • #2
    Instead of a timer in the "worker" thread, you can leave your timer in the mian thread. When the WM_TIMER message is received, you do a SetEvent of an event you created with CreateEvent.

    The "worker" thread does its "Waitfor" on the Event, rather than on the timer.

    MCM


    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Michael.

      I thought of that, but from what I read the second thread
      cant reset the timer, Only the thread that owns the dialog
      can ?
      when the timer fires I need to be able to kill the timer
      so it doesnt fire again while the second thread is still
      working from the first time the timer fired. When the second
      thread is done it needs to restart the timer and go back into
      a waitstate.

      ------------------

      Comment


      • #4
        In your Timer process (don't use WM_TIMER message for the timer) you could call SetEvent as michael suggested then in the timer proc wait for another event (WaitForSingleObject) your thread will signal with SetEvent when it has finished it task. Depending upon the timing required you might even want to look at the multimedia timers. They are very accurate and better for this type of use I feel.

        Ron

        Comment


        • #5
          Thanks Ron, will have a good look at that.
          I take it that by using a separate timer proc the
          waitforsingleobject wont hold up the main message queue ?




          ------------------

          Comment


          • #6
            That's correct. Or in another variation using the WM_TIMER message, you could let the timer continue firing while waiting for the worker thread to signal an event when it has completed its work. Until the event is signaled by the thread the code associated with the WM_TIMER message does nothing.

            Comment


            • #7
              That did it, and with alot less code changes
              thanx guys.

              N.

              ------------------

              Comment

              Working...
              X
              😀
              🥰
              🤢
              😎
              😡
              👍
              👎