0

My specific question is: How to ignore windows events when in a child form called from that event handler?

Some context: My application captures a fingerprint, and puts up the next form (secondForm) when a print is recognized against the database. I want to ignore any prints they put in while their secondForm is up. The trouble is that when people press the print multiple times, or while their secondForm is up, then the events are queued until after the secondForm closes, so I get multiple calls to the event handler for that person.. I've tried so many ways around this, including calling the routine that open secondForm as a delegate(is that even appropriate), putting a global boolean in the event handler, etc. If I disable fingerprint capture during the oncomplete eventhandler, my form never shows up.
Am I missing something obvious to you here? Much gratitude for any ideas...

Imports DPFP.Capture ' DigitalPersona fingerprint reader library
' Simple example to capture a fingerprint from DigitalPersona fingerprint reader.
Public Class SimpleFP
Implements DPFP.Capture.EventHandler

Private mIgnore As Boolean
Public eventHandlerComplete As DPFP.Capture.EventHandler
Public WithEvents mCapture As DPFP.Capture.Capture

Private Sub WaitForFPrint_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Try
        ' set up finger print capture
        mCapture = New DPFP.Capture.Capture
        mCapture.EventHandler = Me
        mCapture.StartCapture()
    Catch ex As Exception
        MsgBox("Problem starting fingerprint reader: " & ex.Message)
    End Try
End Sub

Public Sub FPOnComplete(ByVal Capture As Object, ByVal sernum As String, ByVal sample As DPFP.Sample) _
    Implements DPFP.Capture.EventHandler.OnComplete

    'mCapture.StopCapture()  
    'This is what I want to do, but when I leave this in,  my secondForm won't stay up

    Dim s As String = displaySecondScreen(sample)

    showStatus(s)
    'mCapture.StartCapture()  
     'This is what I want to do, but when I leave this in,  my secondForm won't stay up
End Sub

' Put up second form. This is called from the fingerprint OnComplete event handler.
Private Function displaySecondScreen(ByVal sample As DPFP.Sample) As String

    Dim status As String = "OK"
    Try
        Dim x As DPFP.FeatureSet
        x = extractFeatures(sample)

        ' This is where I match the fp in my code, but I removed here to simplify
        If True Then

            Dim frm As New frmSecondForm
            frm.ShowDialog(Me)
            frm.Dispose()

        Else
            ' No fingerprint match - normal case
            status = "Fingerprint not recognized"
        End If
    Catch ex As Exception
        status = "Exception during fingerprint verification: " & ex.Message
    End Try
    Return status
End Function

' Made rudimentary for this example, but I thought some person new to dpfp  may be able to use this
Private Function extractFeatures(ByVal sample As DPFP.Sample) As DPFP.FeatureSet
    Dim extractor As New DPFP.Processing.FeatureExtraction()
    Dim feedback As New DPFP.Capture.CaptureFeedback()
    Dim features As New DPFP.FeatureSet()
    extractor.CreateFeatureSet(sample, DPFP.Processing.DataPurpose.Verification, feedback, features)
    If feedback = DPFP.Capture.CaptureFeedback.Good Then

    End If
    Return features
End Function

Private Sub debugOut(ByVal s As String)
    Console.WriteLine(s)
End Sub

' Display status on first form
Delegate Sub showStatusCallback(ByVal s As String)

Private Sub showStatus(ByVal s As String)
    If lblStatus.InvokeRequired Then
        Dim d As New showStatusCallback(AddressOf showStatus)
        Me.Invoke(d, New Object() {s})
    Else
        lblStatus.Text = s
    End If
End Sub

' ... followed by other implements dpfp eventhandlers not in use....
' ....

End Class

BonTemps
  • 11
  • 1
  • 4
  • It is very likely that the event is raised on another thread. Which explains why your form is dead, this worker thread doesn't pump a message loop. You'll need to use Me.BeginInvoke() to run code on your UI thread. – Hans Passant Sep 13 '12 at 18:21
  • Thanks Hans. Hmmm, so I just tried that (putting the frm creation and the show dialog in a routine called by beginInvoke, and calling stop & start capture from oncapture event handler), but the same thing happens: the child form flashes and then goes away. I don't really need to call the stop capture and start capture (and if I don't, then the form showdialog is fine...) but maybe there is a way to say "I want to ignore queued ONComplete msgs until I'm done with this child form"? – BonTemps Sep 13 '12 at 18:52
  • You posted no relevant code. Implement the FormClosing event handler and set a breakpoint on it to see why it is closing. – Hans Passant Sep 13 '12 at 18:55
  • Thank you @HansPassant it did work to use BeginInvoke, and now I can put in the .StarCapture and .StopCapture calls (which don't do what I want,... but that's another problem!) Delegate Sub showFormCallback() Private Sub showForm() Dim d As New showFormCallback(AddressOf showForm2) Me.BeginInvoke(d) End Sub Private Sub showform2() Dim f As New frmSecondForm f.Showdialog() End Sub – BonTemps Sep 13 '12 at 20:44

0 Answers0