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