I'm working on a situation that requires the use of multiprocessing.
I need to read files and a bunch of processes that can take some time. During this process, I want to display a sort of window to user (Aguarde...)
without compromising the UI thread and without causing those whitish that occur when the graphical interface is no longer updated.
My thread runs a method that has a return and I am also not able to retrieve the information from this method. I searched the internet, but it was not clear yet. I do not know how to retrieve the data handled by the thread .
My thread runs a method that captures database information, compares it to a text file, and then returns a ArrayList
with the discrepant data. The problem is to know when the process has finished and receive the result of this method.
Private Sub Button2_Click_1(sender As Object, e As EventArgs) Handles Button2.Click
Dim OPF As New OpenFileDialog
Dim Caminho As String
Dim Aviso As New frmWarning
Dim ListaEntradas As ArrayList
If IO.Directory.Exists(Path) Then
Caminho = Path
Else
Caminho = Path.Substring(1, 3)
End If
With OPF
.InitialDirectory = Caminho
.ShowDialog()
End With
Aviso.Show()
Dim compara As New Thread(AddressOf TDNFEntradas)
compara.Start(OPF.FileName)
'ListaEntradas = (E AGORA? COMO RECEBER A LISTA DA THREAD?)
Aviso.Close()
End Sub
Private Function TDNFEntradas(ByVal Endereco As String) As ArrayList
Dim NFentradas As New ArrayList
Dim Mensagem As New frmWarning
Dim Lista As New ArrayList
HabilitarControlesNF(False) ' Desabilita controles do formulario
NFentradas = CapturarNotas(Endereco, 0) ' Carrega Numeros das Notas dentro de um arrayList
Lista = CompNotasEntrada(NFentradas) ' Compara dados da lista com o banco e retorna as diferenças numa outra lista
HabilitarControlesNF(True) 'Habilita controles do formulario
Return Lista 'Retorna lista com discrepancias
End Function