I have set up, in the initialize function, the event handler for each frame:
[videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame);
In the video_newFrame i have all the code i need in my application: it takes the frame, compute it, find the QR code, decode it, check "something" and then show a messageBox; and so on for every frame. My problem is: when i show the qr code, program computes it and the messagebox appears (with the ok button, so app should be stopped); if i get out of the camera field of view the paper with the qr code, i'm expecting that, when i will click on the ok button, it will go on in the code and the next frame will be empty (meaning without the paper with the qr code - so NO messagebox in the next frame!). But it isn't like that! The most of the times, the event handler has already fired up 1-2-3 call to the video_newframe, and that means that i will have another 1-2-3 messagebox. The code is this:
Expand|Select|Wrap|Line Numbers
- private void video_NewFrame2(object sender, NewFrameEventArgs eventArgs)
- {
- Bitmap img = (Bitmap)eventArgs.Frame.Clone();
- var result = reader.Decode(img);
- if (result != null) {
- if (DialogResult.OK == MessageBox.Show("hello!"))
- // do something;
- img.Dispose(); }
- }
Expand|Select|Wrap|Line Numbers
- videoSource.NewFrame -= video_NewFrame; // at the beginning, at first line
- ...
- videoSource.NewFrame += video_NewFrame; // in the if of the DialogResult, in the "// do something"
So i tried with a bool value: i added an if statement that check if the bool value is true and if it is, it puts "bool value = false" (to avoid the next event handling), it does the stuff and if value is false it returns; then, when it is doing the stuff, in the if of the DialogResult, in the "// do something", i've put "bool = true" again. No success for me.
So my problem still remains there: i just want the function to work always; but i want, somehow, that when it finds a result (a qr code) it stops firing events for just the time needed to show only one messagebox; so, for example, stop the event handling or something like that...
Hope you can help me! Thanks in advance! :)