hi . i am using SetTimer(...) combined with OnTimer(...) in my code to call 2 different methods on 2 different timers. Here's a simplified version of my code to make things clear:
SetTimer(1, 100, NULL);
SetTimer(2, 40, NULL);
...
void CMTDlg::OnTimer(UINT nTimerID)
{
if (nTimerID == 1)
{
//capture an image from the webcam and save it in the 'img' folder
}
if (nTimerID == 2)
{
//some processing
}
}
Now, my assumed working of the code was this: After 100 ms timer1 gets fired, OnTimer is called, and an image is saved in the img folder. This repeats every 100 ms. Meanwhile, after every 40 ms, timer2 gets fired, OnTimer is called, and some processing takes place. The capturing of images from the webcam is independent of the the processing in timer2, so regardless of how long that processing takes, my images will be generated every 100 ms by timer1. ie, timer1 and timer2 and mutually independent.
But thats not how its working. The processing in timer2 takes a long time, and this is affecting timer1. timer1 does not generate images every 100 ms now. But if I comment out timer2, then the timer1 generates images fine @ every 100 ms.
So my question is, what am I doing wrong and how can I fix it?
Thanks,
本文探讨了使用SetTimer与OnTimer结合调用不同方法时遇到的问题。在一个涉及两个独立定时器的任务中,作者发现其中一个定时器的长时间处理过程会影响另一个定时器的正常触发频率。文章分析了可能的原因,并寻求解决方案。
3416

被折叠的 条评论
为什么被折叠?



