Referencing main from from within ThreadPool

English_man69

New member
Joined
Sep 21, 2005
Messages
3
Programming Experience
1-3
Referencing main form from within ThreadPool

Hi All,
I am still kinda new to VB.Net, so go easy...

I have established a thread pool that is started from a click event handler. I can get everything in the thread pool to work except when I try to add a picture box to the main form.

The program accesses a web page, does a search, parses the returned web page into an array of id numbers and image links. I have the web page processing done within a thread pool, because otherwise the program appears to freeze while the page is being accessed.

My problem is in trying to create picture boxes within a panel established on the main form from within the thread pool. I get the following error message "reference to a non-shared member requires an object reference".

The Panel already exists and the picture boxes have to be created from within a loop within the Thread Pool. (Though I have tried creating the Panel while in the Thread also to no success)

How can I reference the main form's Panel to add the picture box to it, from within the thread pool?

Thanks a lot!
 
I think this is the applicable code, all within the main form code:

Private Sub searchButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles searchButton.Click
ThreadPool.QueueUserWorkItem(New System.Threading.WaitCallback(AddressOf searchSite), test)
End Sub

Sub searchSite(ByVal searchArg As Object)
Try
Dim SrchArg As searchArgs
SrchArg = CType(searchArg, searchArgs)
SrchArg.modifyArrayReturn = resultIds3
SrchArg.arrayReturn = modifyArray
SrchArg.processPics()
End Try
End Sub

Friend Class searchArgs
Friend makeID, modelID, zipCode As Integer
Friend distance, new_distance As String
Friend modifyArrayReturn, arrayReturn As Array
Sub processPics()
Dim picBoxTemp As New PictureBox
Dim panelTemp As New Panel
' Thread pool dies at this point
panel1.Controls.Add(panelTemp)
panelTemp.Controls.Add(picBoxTemp)
panelTemp.Width = 548
panelTemp.Height = 316
panelTemp.Left = 168
panelTemp.Top = 146
panelTemp.Visible = True
panelTemp.Show()
picBoxTemp.ImageLocation = "http://images.autoextra.com/imgs/design/ag/agescobar/autoorange/image-unavailable-76x57.gif"
End Sub
End Class

 
Back
Top