Visual Basic.NET - No puedo volcar un valor en un TextBox desde un SubProceso

 
Vista:

No puedo volcar un valor en un TextBox desde un SubProceso

Publicado por Jordan Morvae (2 intervenciones) el 28/06/2017 15:15:33
Hola amigos:

La idea es que cuando uno ponga la huella en un lector Finger Print UrU4500 complete en el formulario principal los datos del que puso el dedo. Estos datos si puedo mostrarlos en un MSGBOX, pero el MSGBOX como Uds. saben es limitado, no puedo por ejemplo poner la imagen de que dedo es el que se esta utilizando.

Bue... la cuestion es que me sale el siguiente error:

DPFP.Error.SDKException: Event Handler has generated an Exception ---> System.InvalidOperationException: Cross-thread operation not valid: Control 'TextBox1' accessed from a thread other than the thread it was created on.

Gracias!!!


Aqui les Pongo mi codigo fuente completo.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
Imports System.IO
Imports System.Text
Imports DPFP
Imports DPFP.Capture
Imports MySql.Data.MySqlClient
Imports System.Data
Imports System.Data.SqlClient
Public Class Busqueda
    Implements DPFP.Capture.EventHandler
    Private template As DPFP.Template
    Private captura As DPFP.Capture.Capture
    Private verificador As DPFP.Verification.Verification
    Protected Overridable Sub Init()
        Try
            captura = New Capture()
            If Not captura Is Nothing Then
                captura.EventHandler = Me
                verificador = New Verification.Verification()
                template = New Template()
            Else
                MessageBox.Show("No se pudo instanciar la captura")
            End If
        Catch ex As Exception
            MessageBox.Show("No se pudo instanciar la captura")
        End Try
    End Sub
    Protected Sub iniciarCaptura()
 
        If Not captura Is Nothing Then
            Try
                captura.StartCapture()
            Catch ex As Exception
                MessageBox.Show("No se pudo instanciar la captura")
            End Try
        End If
    End Sub
 
    Protected Sub pararCaptura()
        If Not captura Is Nothing Then
            Try
                captura.StopCapture()
            Catch ex As Exception
                MessageBox.Show("No se pudo detener la captura")
            End Try
        End If
    End Sub
    Private Sub ponerImagen(ByVal bmp)
        imagenHuella.Image = bmp
    End Sub
    Private Sub ponerMensaje(ByVal texto)
 
 
        TextBox1.Text = texto '------------------------> DA ERROR
 
 
    End Sub
    Protected Function ConvertirSampleAMapaDeBits(ByVal Sample As DPFP.Sample)
        Dim convertidor As New DPFP.Capture.SampleConversion()
        Dim mapaBits As Bitmap = Nothing
        convertidor.ConvertToPicture(Sample, mapaBits)
        Return mapaBits
    End Function
 
    Protected Function extraerCaracteristicas(ByVal Sample As DPFP.Sample, ByVal Purpose As DPFP.Processing.DataPurpose) As DPFP.FeatureSet
        Dim extractor As New DPFP.Processing.FeatureExtraction()
        Dim alimentacion As DPFP.Capture.CaptureFeedback = DPFP.Capture.CaptureFeedback.None
        Dim caracteristicas As New DPFP.FeatureSet()
        extractor.CreateFeatureSet(Sample, Purpose, alimentacion, caracteristicas)
        If (alimentacion = DPFP.Capture.CaptureFeedback.Good) Then
            Return caracteristicas
        Else
            Return Nothing
        End If
    End Function
 
    Public Sub OnComplete(Capture As Object, ReaderSerialNumber As String, Sample As Sample) Implements EventHandler.OnComplete
        ponerMensaje("prueba")
        ponerImagen(ConvertirSampleAMapaDeBits(Sample))
        Dim caracteristicas As DPFP.FeatureSet = extraerCaracteristicas(Sample, DPFP.Processing.DataPurpose.Verification)
        If Not caracteristicas Is Nothing Then
 
            Dim result As New DPFP.Verification.Verification.Result()
            Dim builderconex As New MySqlConnectionStringBuilder()
            builderconex.Server = "127.0.0.1"
            builderconex.UserID = "root"
            builderconex.Password = ""
            builderconex.Database = "fingerprint"
            Dim conexion As New MySqlConnection(builderconex.ToString())
            conexion.Open()
            Dim cmd As New MySqlCommand()
            cmd = conexion.CreateCommand
            cmd.CommandText = "SELECT * FROM usuarios"
            Dim read As MySqlDataReader
            read = cmd.ExecuteReader()
            Dim verificado As Boolean = False
            Dim nombre As String = ""
            Dim cedula As String = ""
            Dim dedo As String = ""
            While (read.Read())
                nombre = read("Nombre")
                cedula = read("Cedula")
                dedo = read("Dedo")
                Dim memoria As New MemoryStream(CType(read("huella"), Byte()))
                template.DeSerialize(memoria.ToArray())
                verificador.Verify(caracteristicas, template, result)
                If (result.Verified) Then
                    nombre = read("nombre")
                    cedula = read("Cedula")
                    dedo = read("Dedo")
                    verificado = True
                    Exit While
                End If
            End While
            If (verificado) Then
                Dim mensaje As String
                mensaje = String.Concat(nombre, " ", cedula, " ", dedo)
                'txtLectura.Text = "Hola Mundo"
                'Me.txtNombre = mensaje
                MessageBox.Show(mensaje)  '----------------> INVOCA A UNA SUB PARA VER SI LOGRA SOLUCIONAR EL PROBLEMA
                ponerMensaje(mensaje)
                'MessageBox.Show(nombre)
                'MessageBox.Show(cedula)
                'MessageBox.Show(dedo)
            Else
 
                MessageBox.Show("No se encontro ningun registro")
 
 
            End If
            read.Dispose()
            cmd.Dispose()
            conexion.Close()
            conexion.Dispose()
        End If
    End Sub
 
    Public Sub OnFingerGone(Capture As Object, ReaderSerialNumber As String) Implements EventHandler.OnFingerGone
 
    End Sub
 
    Public Sub OnFingerTouch(Capture As Object, ReaderSerialNumber As String) Implements EventHandler.OnFingerTouch
 
    End Sub
 
    Public Sub OnReaderConnect(Capture As Object, ReaderSerialNumber As String) Implements EventHandler.OnReaderConnect
 
    End Sub
 
    Public Sub OnReaderDisconnect(Capture As Object, ReaderSerialNumber As String) Implements EventHandler.OnReaderDisconnect
 
    End Sub
 
    Public Sub OnSampleQuality(Capture As Object, ReaderSerialNumber As String, CaptureFeedback As CaptureFeedback) Implements EventHandler.OnSampleQuality
 
    End Sub
 
    Private Sub Busqueda_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Init()
        iniciarCaptura()
 
    End Sub
 
    Private Sub Busqueda_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
        pararCaptura()
    End Sub
 
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnEnrolar.Click
        pararCaptura()
        Dim ventanaEnrolar As New ventanaEnrolar()
        ventanaEnrolar.ShowDialog()
 
    End Sub
End Class
 
Friend Class Enrolar
    Public Sub New()
    End Sub
End Class
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

No puedo volcar un valor en un TextBox desde un SubProceso

Publicado por Jordan Morvae (2 intervenciones) el 28/06/2017 16:12:32
Ya solucione... de todos modos.... gracias!!!!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar