I am using background threads to run intense search processes in order to allow the UI to be fully accessible. After creating each bgw I update a datagridview which shows the different threads and current status. however once they complete, I have no way or at least I dont know of a way to update the status on the datagridview specific to each backgroundworker.
Try
bgw.RunWorkerAsync()
queuelist.Enqueue(bgw)
If Not Thread.CurrentThread.Name = "Main Thread" Then
Dim record As String() = {jobNum, clientProj & jobNum, jobStartTime, bgw.IsBusy.ToString}
DataGridView1.Rows.Add(record)
End If
Catch ex As Exception
MessageBox.Show("An Error Occured:" & vbNewLine & ex.Message)
End Try
this sets the datagridviewer once the threads begin, but once it ends I dont know how to update or know which thread ended. I tried putting them into a queue but I cannot identify a specific worker when i dequeue.
any ideas
I really don’t understand why you’d make implementation details like background workers visible on the user interface. Well, some code. It doesn’t make sense to use a Queue, threads do not end in any predictable order. Let’s do a list:
You want to take advantage of the RunWorkerCompleted event raised by BGW to know when the job is done. So use AddHandler:
And the event handler can look like this: