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. Timer in MFC

Timer in MFC

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestioncareer
8 Posts 5 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.
  • J Offline
    J Offline
    jossion
    wrote on last edited by
    #1

    I have a 3 thread MFC application. Out of these one sub thread should be used for displaying video at intervals of 40ms. How do i create a periodic timer to accomplish this job. I have seen the SetTimer function. How to manage the timer from the display thread. How to get the parameters such as HWND,TimerProc parameter etc.

    _ N K D 4 Replies Last reply
    0
    • J jossion

      I have a 3 thread MFC application. Out of these one sub thread should be used for displaying video at intervals of 40ms. How do i create a periodic timer to accomplish this job. I have seen the SetTimer function. How to manage the timer from the display thread. How to get the parameters such as HWND,TimerProc parameter etc.

      _ Offline
      _ Offline
      __yash__
      wrote on last edited by
      #2

      Try the following: //You can set the timer in one of the funtions of some class //probably in some constructor //m_nTimer1 will be declared as unsigned int in that class m_nTimer1 =CWnd::SetTimer(1,40,0);//for 40 ms //After 40 ms the following function will get called void YourClass::OnTimer(UINT nIDEvent) { if(nIDEvent==1) { CWnd::KillTimer(m_nTimer1); /***Call your display function here****/ m_nTimer1 =CWnd::SetTimer(1,40,0);//Then again set your timer //for 40 ms } }

      1 Reply Last reply
      0
      • J jossion

        I have a 3 thread MFC application. Out of these one sub thread should be used for displaying video at intervals of 40ms. How do i create a periodic timer to accomplish this job. I have seen the SetTimer function. How to manage the timer from the display thread. How to get the parameters such as HWND,TimerProc parameter etc.

        N Offline
        N Offline
        Nishad S
        wrote on last edited by
        #3

        Since you have a thread to show the video, timer is not needed. You can use Sleep API in the loop. But the problem is that it cannot give you a much precision. You have to play the video on by looking at the time (I think GetTickCount is useful) instead of using sleep for a real time video show.

        - NS -

        1 Reply Last reply
        0
        • J jossion

          I have a 3 thread MFC application. Out of these one sub thread should be used for displaying video at intervals of 40ms. How do i create a periodic timer to accomplish this job. I have seen the SetTimer function. How to manage the timer from the display thread. How to get the parameters such as HWND,TimerProc parameter etc.

          K Offline
          K Offline
          KarstenK
          wrote on last edited by
          #4

          For the display of the video should use the main MFC thread (your app). So use the normal OnTimer() handling. For standard use I create a main MFC app, and for special use a "worker" thread for communicating with devices or greater mathematical operations.

          Greetings from Germany

          J 1 Reply Last reply
          0
          • K KarstenK

            For the display of the video should use the main MFC thread (your app). So use the normal OnTimer() handling. For standard use I create a main MFC app, and for special use a "worker" thread for communicating with devices or greater mathematical operations.

            Greetings from Germany

            J Offline
            J Offline
            jossion
            wrote on last edited by
            #5

            I am using CreateThread() function to create worker threads. Are there any other ways to create threads in MFC applications. Why I have this doubt is because my application is utilizing full 100% of CPU all the time. My application has one serial port reading thread which should take only very little CPU another a fully mathematical thread and third a display thread.

            K D 2 Replies Last reply
            0
            • J jossion

              I am using CreateThread() function to create worker threads. Are there any other ways to create threads in MFC applications. Why I have this doubt is because my application is utilizing full 100% of CPU all the time. My application has one serial port reading thread which should take only very little CPU another a fully mathematical thread and third a display thread.

              K Offline
              K Offline
              KarstenK
              wrote on last edited by
              #6

              The high CPU utilization is very bad. It is in best case a missdesign in worst a bug. :doh: Identify and eliminate this via Sleep(), a Timer or Waiting for a Event.

              Greetings from Germany

              1 Reply Last reply
              0
              • J jossion

                I have a 3 thread MFC application. Out of these one sub thread should be used for displaying video at intervals of 40ms. How do i create a periodic timer to accomplish this job. I have seen the SetTimer function. How to manage the timer from the display thread. How to get the parameters such as HWND,TimerProc parameter etc.

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #7

                jossion wrote:

                Out of these one sub thread should be used for displaying video at intervals of 40ms. How do i create a periodic timer to accomplish this job.

                You probably shouldn't, since the primary thread owns the UI. Instead, have the secondary thread post a message to the primary thread indicating what needs to be displayed.


                "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                1 Reply Last reply
                0
                • J jossion

                  I am using CreateThread() function to create worker threads. Are there any other ways to create threads in MFC applications. Why I have this doubt is because my application is utilizing full 100% of CPU all the time. My application has one serial port reading thread which should take only very little CPU another a fully mathematical thread and third a display thread.

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #8

                  jossion wrote:

                  I am using CreateThread() function to create worker threads. Are there any other ways to create threads in MFC applications.

                  With MFC, you should be using AfxBeginThread().


                  "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                  "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                  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