Reputation: 1
I am creating a self enrollment system for a biometrics system. I was trying to create a loop mix with timer. I want to capture an image then stop the timer, and wait for 5 sec and capture again for 5 times. I was trying to use thread.sleep, but it will make my picturebox stop streaming the video. But according to the codes below, it will straight away capture 5 images , and non-stop looping. Please correct me. Thanks (5 sec timer > capture > timer stop ) * 5 times and finally all stop
private void timer1_Tick(object sender, EventArgs e)
{
int a = 1;
/* while loop execution */
while (a < 5)
{
CaptureFunction();
a++;
timer1.Stop();
}
timer1.Start();
}
Upvotes: 0
Views: 822
Reputation: 4082
You can change the timer's interval so it only fires every 5 seconds:
http://msdn.microsoft.com/en-us/library/system.windows.forms.timer.interval(v=vs.100).aspx
5000 is equivalent to 5 seconds. Then use this code:
int photosTaken = 0;
private void timer_Tick(object sender, EventArgs e)
{
CaptureFunction();
photosTaken++;
if(photosTaken == 5) { timer.Stop(); }
}
If you wish to capture another 5, use this function:
private void capture5()
{
photosTaken = 0;
timer.Start();
}
Upvotes: 1
Reputation: 4542
This should solve:
int a = 1;
private void timer1_Tick(object sender, EventArgs e)
{
if(a <= 5)
{
CaptureFunction();
a++;
}
else
timer1.Stop();
//place this just in case....
}
oh...and if you really want to place the messagebox,place it after the increment(a++).
Upvotes: 0