Quantcast
Viewing all articles
Browse latest Browse all 12583

Time between ticks seems to get faster

Hi

I have a program in which I want to replay some images in a sequence stored in a ringbuffer (this is from an SDK which comes with my camera). I have a function loadimage(string FrameNumber) which will load an image to my display.

I have a timer called replaytimer on my form. When I click a button called replayButton the images start playing through in a sequence. When I click pauseButton the images stop playing. This all works. My problem is that when I then click replay again the images start scrolling through twice as fast. Click pause and replay again and they go even faster etc. I think I must be generating either an extra timer or tick each time I run the code but can't figure it out. The relevant code is below.

 private void replayButton_Click(object sender, EventArgs e)
    {
        replaytimer.Interval = 20;
        replaytimer.Enabled = true;
        replaytimer.Tick += new EventHandler(replaytimer_Tick);
        replaytimer.Start();

    }


 private void replaytimer_Tick(object sender, EventArgs e)
    {
        int currFrame = Int32.Parse(currFrameVal.Text);
        int lastframeval = Int32.Parse(lastFrame.Text);
        int firstframeval = Int32.Parse(firstFrame.Text);

        if (currFrame >= lastframeval - 1)
        {
            currFrame = firstframeval;
        }
        else
            currFrame++;

        currFrameVal.Text = currFrame.ToString();
        loadFrame(currFrame.ToString());

        time++;

    }

 private void pauseButton_Click(object sender, EventArgs e)
    {
        replaytimer.Stop();
        replaytimer.Dispose();
    }

currFrameVal etc are values from text boxes.

Any help would be really appreciated


Viewing all articles
Browse latest Browse all 12583

Trending Articles