Well, it works, after a fashion.
For a 5 second run at 30 fps, the loop completes in 4.969 seconds and missed 8 frames, (0.05333 frame loss ratio) which I attribute to converting 33.3333 ms per frame to an int and then dividing 33 by two.
My code for the loop:
private void CaptureLoop()
{
int delay = Convert.ToInt32(frameDelay);
if(delay ==33)
delay=delay/2;
refTick=System.Environment.TickCount;
while(!stop&&((TotalFramesAcquired+missed)<local_config.MaxFramesAcquire))//this.nUDTotalFrames.Value))
{
curTick=System.Environment.TickCount;
if (!dt.AcquireFrame(TotalFramesAcquired++))
{
TotalFramesAcquired--;
}
decimal oops = (curTick-refTick)/((TotalFramesAcquired + missed) *frameDelay);
ticks.Add(curTick);
if (oops > 1m)
{
missed+= Convert.ToInt32(Math.Round(oops,0));
}
System.Threading.Thread.Sleep(delay);
Application.DoEvents();
this.pbarCapture.Value=TotalFramesAcquired;
}
ContinuousStop();
}
I found that the system was taking twice as long to finish an acquisition run and also counting a number of 'misses' equal to the number of frames that were supposed to be captured. So, I hacked it and applied the /2. I get the feeling that I'll need to do something similar for the 15fps setting, only I'll be dividing by three.
Any ideas why the loop is so slow?
I tried setting the priority of this thread to highest, but that only ended up making the application take much longer to load.