Frames not updating in loop
===

Here's my relevant code:

In the form's load method:

    Application.Idle += new EventHandler(delegate(object s, EventArgs ea)
    {
        if (!recording)
        {
            currentFrame = getFrame();
            ib.Image = currentFrame;
        }
        else
        {
            ib.Image = recFrame;
        }
        });


On a button press (ib is an ImageBox on the form):

    Measurements measurements = new Measurements();
    String name = txtSampleName.Text;
    ib.Image = recFrame;
    stopwatch.Start();
    recording = true;
    while ((count = (int)Math.Floor(stopwatch.ElapsedMilliseconds/(double)1000)) < finalTime)
    {
        currentFrame = getFrame();
        ib.Image = currentFrame;               
        Measurement currentMeasurement = new Measurement(name, currentFrame);
        measurements.add(currentMeasurement);
    }
    recording = false;
    stopwatch.Stop();
    measurements.write(txtDirectory.Text);

The problem is that the frame isn't actually updating. currentFrame takes the value of whatever the frame was before the loop starts. recFrame doesn't become visible in ib.Image - ib just hangs for the duration of the loop - and not filled with recFrame as it should be). currentMeasurement is added to the measurements list as it should be, but the frame in it is not the current frame from the camera. Here's a summary of the code from getFrame(), which is either not returning what is from the webcam at the current time, or is and currentFrame is taking its old value regardless:

    private Image<Bgr, Byte> getFrame()
    {
        // get the frame
        Image<Bgr, Byte> frame = capture.QueryFrame();

        // draw some stuff on top of the frame
        // ...

        // return
        return frame;
    }

Do I need to add some sort of delay to wait for something to complete? I've tried putting in a Thread.Sleep and it doesn't help anything. I don't understand what the problem is, so haven't been able to look for a sensible solution. When I later export the frames in measurements to an AVI file, all the frames have the value of currentFrame before the loop started, and do not change.

Any ideas?

With many thanks,

Froskoy.