vb.net 应用程序在不活动(未聚焦)时不监听指纹 reader

vb.net app does not listen Fingerprint reader when is inactive (not in focus)

我使用 DigitalPersona SDK OneTouch for .NET 在 Visual Basic 中创建了一个应用程序,该应用程序将指纹 reader "U.are.U 4500" 中扫描的指纹与存储在文件夹中的指纹进行比较。该应用程序只要处于活动状态 window(在所有打开的应用程序中)就可以正常工作,而且我需要它始终收听 reader,即使它已最小化或未处于活动状态应用程序。我试过使用后台工作者,将表单设置为 属性 TopMost True,制作服务,甚至在调用事件停用时将表单设置为活动状态,但此替代方案的 none 有效。如果有任何帮助,我将不胜感激,在此先感谢您的建议。

这是我的 vb.net 应用程序的代码。

Public Class CaptureForm
    Implements DPFP.Capture.EventHandler

    Private Template As DPFP.Template
    Private Verificator As DPFP.Verification.Verification
    Private Capturer As DPFP.Capture.Capture

    Private Sub CaptureForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If BackgroundWorker1.IsBusy <> True Then
            BackgroundWorker1.RunWorkerAsync()
        End If
    End Sub

    Private Sub CaptureForm_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
        StopCapture()
    End Sub

    'Private Sub CaptureForm_Deactivate(ByVal sender As System.Object, ByVal e As EventArgs) Handles MyBase.Deactivate
    '    Me.Activate()
    'End Sub
    'Private Sub CaptureForm_Activate(ByVal sender As System.Object, ByVal e As EventArgs) Handles MyBase.Activated

    'End Sub

    Sub Init()
        Try
            Capturer = New DPFP.Capture.Capture()
            If (Not Capturer Is Nothing) Then
                Capturer.EventHandler = Me
            End If
        Catch ex As Exception
            MessageBox.Show("No se pudo iniciar la operación de captura!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
        Verificator = New DPFP.Verification.Verification()
        StartCapture()
    End Sub

    Protected Overridable Sub Process(ByVal Sample As DPFP.Sample)

        ' Process the sample and create a feature set for the enrollment purpose.
        Dim features As DPFP.FeatureSet = ExtractFeatures(Sample, DPFP.Processing.DataPurpose.Verification)

        ' Check quality of the sample and start verification if it's good
        If Not features Is Nothing Then
            Dim result As DPFP.Verification.Verification.Result = New DPFP.Verification.Verification.Result()

            Dim foundFile As String

            Dim fileReader As String
            fileReader = My.Computer.FileSystem.ReadAllText("templates.txt")
            Dim flag As Boolean

            flag = False

            For Each foundFile In My.Computer.FileSystem.GetFiles(fileReader, FileIO.SearchOption.SearchTopLevelOnly, "*.fpt")
                Using fs As IO.FileStream = IO.File.OpenRead(foundFile)
                    Dim template1 As New DPFP.Template(fs)
                    Me.Template = template1
                End Using
                Verificator.Verify(features, Template, result)
                If result.Verified Then

                    flag = True
                    Dim file As System.IO.StreamWriter
                    Dim file2 As String
                    Dim nombre As String = My.Computer.FileSystem.GetName(foundFile)
                    file2 = nombre.Remove(nombre.Length - 4, 4)
                    'MsgBox(file2)
                    file = My.Computer.FileSystem.OpenTextFileWriter("ingreso.txt", False)
                    file.WriteLine(file2)
                    file.Close()
                    Exit For
                End If
            Next
            If flag = False Then

            End If
        End If
    End Sub
    Protected Function ExtractFeatures(ByVal Sample As DPFP.Sample, ByVal Purpose As DPFP.Processing.DataPurpose) As DPFP.FeatureSet

        Dim extractor As New DPFP.Processing.FeatureExtraction()    ' Create a feature extractor
        Dim feedback As DPFP.Capture.CaptureFeedback = DPFP.Capture.CaptureFeedback.None
        Dim features As New DPFP.FeatureSet()
        extractor.CreateFeatureSet(Sample, Purpose, feedback, features) ' TODO: return features as a result?
        If (feedback = DPFP.Capture.CaptureFeedback.Good) Then
            Return features
        Else
            Return Nothing
        End If

    End Function

    Protected Sub StartCapture()
        If (Not Capturer Is Nothing) Then
            Try
                Capturer.StartCapture()
            Catch ex As Exception

            End Try
        End If
    End Sub

    Protected Sub StopCapture()

        If (Not Capturer Is Nothing) Then
            Try
                Capturer.StopCapture()
            Catch ex As Exception

            End Try
        End If
    End Sub

    Sub OnComplete(ByVal Capture As Object, ByVal ReaderSerialNumber As String, ByVal Sample As DPFP.Sample) Implements DPFP.Capture.EventHandler.OnComplete
        Process(Sample)
    End Sub

    Sub OnFingerGone(ByVal Capture As Object, ByVal ReaderSerialNumber As String) Implements DPFP.Capture.EventHandler.OnFingerGone

    End Sub

    Sub OnFingerTouch(ByVal Capture As Object, ByVal ReaderSerialNumber As String) Implements DPFP.Capture.EventHandler.OnFingerTouch

    End Sub

    Sub OnReaderConnect(ByVal Capture As Object, ByVal ReaderSerialNumber As String) Implements DPFP.Capture.EventHandler.OnReaderConnect

    End Sub

    Sub OnReaderDisconnect(ByVal Capture As Object, ByVal ReaderSerialNumber As String) Implements DPFP.Capture.EventHandler.OnReaderDisconnect

    End Sub

    Sub OnSampleQuality(ByVal Capture As Object, ByVal ReaderSerialNumber As String, ByVal CaptureFeedback As DPFP.Capture.CaptureFeedback) Implements DPFP.Capture.EventHandler.OnSampleQuality

    End Sub

    Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
        Init()
    End Sub
End Class

你完成了最难的部分,只漏了这个

Verificator = New DPFP.Verification.Verification()
Capturer.Priority = DPFPDevXLib.DPFPCapturePriorityEnum.CapturePriorityHigh
StartCapture()

此外,该应用程序必须 运行 在管理员下才能运行高优先级。 ** 高优先级意味着您的应用会收到所有事件,无论它是否最小化。

对我来说这是解决方案:

Public snwr As String
snwr = readers(0).SerialNumber

Protected Overridable Sub Init()
        Try<br>
            **Capturer = New  DPFP.Capture.Capture(snwr,DPFP.Capture.Priority.High)
            If (Not Capturer Is Nothing) Then
                Capturer.EventHandler = Me
            End If<br>
        Catch ex As Exception<br>
            MessageBox.Show("Can't initiate capture operation!", "Error",
            MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
End Sub