2
I am working on a situation that requires the use of multiprocessing.
I need to read files and a shitload of lawsuits that could take some time. During this process, I want to display a kind of user window (Aguarde...)
without compromising the UI thread and without causing the whitish ones that occur when the graphical interface is no longer updated.
However, it is difficult to know when the thread has finished its work, because the process has no set time and can vary according to the volume of information handled and the configuration of the machine. Searching the internet, I found the Join method, responsible for waiting for the end of the threads processing. However I am obliged to stipulate a time for him to leave the waiting mode and as I mentioned before, the process can take from little to long.
My thread performs a method that has feedback and I am also unable to retrieve the information from this method. I searched on the internet, but it is not clear yet. I do not know how to recover the data processed by thread.
My thread executes 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 ended 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
You can place code examples of your thread implementation?
– Leonel Sanches da Silva