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 / C++ / MFC
  4. SetTimer ?

SetTimer ?

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
6 Posts 4 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
    Brian van der Beek
    wrote on last edited by
    #1

    I have a dialog with a button and a progressbar. When the user clicks the button a lengthy process is initiated. During this process I want to increment the progressbar on a regular interval. I did this by setting a timer when the button is clicked, but the OnTimer function is never called. However it is called when I set the timer in the OnInitDialog function. It seems that the lengthy process that is initiated in the 'OnMyButtonClicked' function blocks the timer. Anyone knows a sollution for this problem?

    M J J 3 Replies Last reply
    0
    • B Brian van der Beek

      I have a dialog with a button and a progressbar. When the user clicks the button a lengthy process is initiated. During this process I want to increment the progressbar on a regular interval. I did this by setting a timer when the button is clicked, but the OnTimer function is never called. However it is called when I set the timer in the OnInitDialog function. It seems that the lengthy process that is initiated in the 'OnMyButtonClicked' function blocks the timer. Anyone knows a sollution for this problem?

      M Offline
      M Offline
      Maximilien
      wrote on last edited by
      #2

      you need to have event pumped into your lenghty process. I thing there are samples here on code project, have a look around.


      Maximilien Lincourt "Never underestimate the bandwidth of a station wagon filled with backup tapes." ("Computer Networks" by Andrew S Tannenbaum )

      1 Reply Last reply
      0
      • B Brian van der Beek

        I have a dialog with a button and a progressbar. When the user clicks the button a lengthy process is initiated. During this process I want to increment the progressbar on a regular interval. I did this by setting a timer when the button is clicked, but the OnTimer function is never called. However it is called when I set the timer in the OnInitDialog function. It seems that the lengthy process that is initiated in the 'OnMyButtonClicked' function blocks the timer. Anyone knows a sollution for this problem?

        J Offline
        J Offline
        jhwurmbach
        wrote on last edited by
        #3

        Brian van der Beek wrote: When the user clicks the button a lengthy process is initiated. Do this lengthy progress in a worker thread. Have this worker thread send PostMessages to its parent(View), which in turn sets the Progress bar. For threads, I recommend this article.[^] [edit] You can also use a message pump as suggested (code is in the Prosise-book), but that tends to get complicated.


        Who is 'General Failure'? And why is he reading my harddisk?!?

        B 1 Reply Last reply
        0
        • J jhwurmbach

          Brian van der Beek wrote: When the user clicks the button a lengthy process is initiated. Do this lengthy progress in a worker thread. Have this worker thread send PostMessages to its parent(View), which in turn sets the Progress bar. For threads, I recommend this article.[^] [edit] You can also use a message pump as suggested (code is in the Prosise-book), but that tends to get complicated.


          Who is 'General Failure'? And why is he reading my harddisk?!?

          B Offline
          B Offline
          Brian van der Beek
          wrote on last edited by
          #4

          I now use a worker thread and everything works fine. Thanks for your reply.

          J 1 Reply Last reply
          0
          • B Brian van der Beek

            I have a dialog with a button and a progressbar. When the user clicks the button a lengthy process is initiated. During this process I want to increment the progressbar on a regular interval. I did this by setting a timer when the button is clicked, but the OnTimer function is never called. However it is called when I set the timer in the OnInitDialog function. It seems that the lengthy process that is initiated in the 'OnMyButtonClicked' function blocks the timer. Anyone knows a sollution for this problem?

            J Offline
            J Offline
            John R Shaw
            wrote on last edited by
            #5

            In Win32 you should use a worker thread to handle lengthy processes in the background so that normal message passing can continue. If you do not want to use a worker thread then you will need to to use one of the old tricks used before mult-threading. 1) Use some thing like this if( PeekMessage(...) ) // in lengthy process loop { DispatchMessage(...) } to allow other messages to be processed. OR 2) Use a user defined message that you keeping posting to your self until the job is fininish. There by allowing other messages to flow. This works as follows: PostMessage(MY_MESSAGE); // Get processing started ... Proc(MY_MESSAGE) { swicth(message) { case MY_MESSAGE: // do part of processing if( !done ) PostMessage(MY_MESSAGE); break. } Both of the above method will increase the amount of time it take to do the lengthy process, but they both work to solve your problem. I hope this give you some ideas as to how to solve your problem. INTP

            1 Reply Last reply
            0
            • B Brian van der Beek

              I now use a worker thread and everything works fine. Thanks for your reply.

              J Offline
              J Offline
              jhwurmbach
              wrote on last edited by
              #6

              Brian van der Beek wrote: I now use a worker thread You did this within 20 minutes? :omg: Wow - you code pretty fast! :)


              Who is 'General Failure'? And why is he reading my harddisk?!?

              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