i have created 10 Backgroundworkers in code, and i assign them the same DoWork, ProgressChanged and RunWorkerCompleted like this
Private bwkWorkers As New List(Of BackgroundWorker)
private sub startworking()
For index As Integer = 1 To Me.maxThreadCount Step 1
worker = New BackgroundWorker
worker.WorkerReportsProgress = True
worker.WorkerSupportsCancellation = True
Me.bwkWorkers.Add(worker)
AddHandler worker.DoWork, AddressOf DoWork
AddHandler worker.ProgressChanged, AddressOf ProgressChanged
AddHandler worker.RunWorkerCompleted, AddressOf RunWorkerCompleted
worker.RunWorkerAsync(Me.workIndex)
Next
end sub
the fear i have is in the dowork sub would the backgroundworkers not overwrite the same variable
Private Sub DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs)
Dim worker As BackgroundWorker = DirectCast(sender, BackgroundWorker)
Dim workItem As String = DirectCast(e.Argument.ToString, String)
If worker IsNot Nothing AndAlso workItem IsNot Nothing Then
WorkData = GetWebpagePageContent(urlrlist(cint(workItem)))
If WorkData > 50 Then
Else
End If
End If
End Sub
how do i make sure that each thread does not overwrite the variable in the DoWork before one thread finish with it.
Considering Snylock, would it not cause performance issue?, or should i put the work needed to be done in another sub and call it from DoWork?