Calling functions on seperate threads

Mondeo

Centurion
Joined
Nov 10, 2006
Messages
128
Location
Sunny Lancashire
I've been given a project that i'm about to start. Its basic function is to connect to 6 or 7 websites, fill out some form data and then scape some information from the results pages and display it to the user. Its for price comparison, similar to confused.com.

Each site it connects to takes about 30 seconds to get to the results, so I was hoping to connect them all concurrently on seperate threads.

There will be seven different functions which all return the same custom object. Can I call these functions on different threads? How would I go about it?

Thanks
 
Depending on how you are communicating with the server(s) this might be easy enough to do. If you are using the HttpWebRequest class to communicate it offers a Begin / End GetResponse pair of methods that could be used.

If you give a bit more detail about how you are currently approaching the problem then we can offer a bit more specific advice.
 
Hi PD,

I'm manipulating the controls of each web page inside a web browser control.

Basic Example:
Code:
Private Function GetCurrentWebDoc() As mshtml.HTMLDocument
Try
Return DirectCast(wb.Document, mshtml.HTMLDocument)
Catch ex As Exception
Return Nothing
End Try
End Function

Private Function GetCurrentWebForm() As mshtml.HTMLFormElement
Try
If GetCurrentWebDoc.forms.length > 0 Then
Return DirectCast(GetCurrentWebDoc.forms.item(0), mshtml.HTMLFormElement)
Else
Return Nothing
End If
Catch ex As Exception
Return Nothing
End Try
End Function

Private Sub SetTextareaText(ByVal Text As String)
DirectCast(GetCurrentWebForm.item("txtArea"), mshtml.HTMLTextAreaElement).value = Text
End Sub

Private Sub ClickNormalButton()
DirectCast(GetCurrentWebForm.item("cmdClickMe", 0), mshtml.HTMLButtonElement).click()
End Sub

I was thinking about having 7 web browser controls, all invisible which are manipulated on 7 threads with the results being returned as they complete to the UI thread.

Is this the correct approach do you think?

Thanks
 
You might find it pretty nasty to work with multiple controls in that way from multiple threads - you shouldn't interact with the UI (or UI controls) from anything other than the main UI thread.

It might be better in the long run to see if it's possible to just post the correct values to the site and read the returned response directly.
 
Back
Top