I create a timer for count down (set to 5 secs) for photo taking using my webcam.
It start with 5, 4, 3, 2, 1 and when its reaches 0, I will call the webcam function to snap the picture.
The number of seconds is display via a label.
Problem with the timer, it was not exactly 1 seconds apart and I can see the screen refresh stops for more than 2 seconds or more before it number in the label changed.
Anyone can help ?
It start with 5, 4, 3, 2, 1 and when its reaches 0, I will call the webcam function to snap the picture.
The number of seconds is display via a label.
Problem with the timer, it was not exactly 1 seconds apart and I can see the screen refresh stops for more than 2 seconds or more before it number in the label changed.
Anyone can help ?
C#:
public System.Windows.Forms.Timer tmrTakePhotoCountdown = new System.Windows.Forms.Timer();
tmrTakePhotoCountdown.Interval = 1000;
tmrTakePhotoCountdown.Tick += new System.EventHandler(this.tmrTakePhoto_Tick);
private void GotoTakePhoto()
{
initCamera();
// start countdown
int takePhotoCountDown = 5; //5 secs
CountDown(takePhotoCountDown);
}
DateTime start;
int timeLeft;
public void CountDown(int seconds)
{
start = DateTime.Now;
timeLeft = seconds;
tmrTakePhotoCountdown.Start();
lblCountdown.Visible = true; //label to display seconds to phototake
lblCountdown.Text = timeLeft.ToString();
}
private void tmrTakePhoto_Tick(object sender, EventArgs e)
{
lblCountdown.Text = timeLeft.ToString();
timeLeft -= 1;
if (timeLeft < 0)
{
tmrTakePhotoCountdown.Stop();
videoCaptureDevice.Stop();
lblCountdown.Visible = false;
pixTakePhotoAccept.Visible = true;
pixTakePhotoRetake.Visible = true;
pixTakePhotoCancel.Visible = true;
}
}