Using timers in vc++ via SetTimer and OnTimer

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,

你可能感兴趣的:(IE,vc++)