Avatar billede gemini73 Nybegynder
01. juni 2004 - 11:16 Der er 1 kommentar

AxWebBrowser / Threading - URGENT PLEASE HELP!

Ok here goes, I've been recommended to become a member at Eksperten since you guys, as a friend of mine so gently put it "are the sh*t*" - ie your are apparently GREAT =)

So what I'm doing (a bit simplified) is a client-application that will loop through an array. This array holds certain data that are supposed to be sent to webbpages in an instance of the AxWebBrowser (ok, what I'm doing is automating the handling of a couple of forms that exists on one of my associates webpages).
Short and descriptive example of this could look something like this (please note that some of the syntax below may be fault - that is ok, what I'm after is the threading)
----------------------------------------------------------------------------
' #1 we asume that we already have an instance of the AxWebBrowser named "formBrowser", which also is placed on the form of the application (applied by simply dragging it to the form)

' #2 here goes the SUB that will be the thread
private sub parseMyForm()
    thisArr(0,0) = "firstName" 'label of the formfield - exists on the first page
    thisArr(0,1) = "Johan" 'value for the formfield

    thisArr(1,0) = "btnSubmit" 'label of the formfield - in this case suggesting a submit button - exists on the first page
    thisArr(1,1) = "click()" 'which should be the event to execute... more on this later

    thisArr(2,0) = "lastName" 'label of the formfield - since this is after the submit-button this would exist on the _2nd_ page
    thisArr(2,1) = "andersson" 'value of the formfield above
    'etc etc etc LOL

    dim i as integer = 0
    For i = 0 To UBound(thisArr, 1) 'looping throught the entire array
        if thisArr(i,1) = "click()" then 'click the appropriate item - usually resulting in a submit
            formBrowser.Document.All(CStr(thisArr(i, 0))).Click()
        else
            ' just fill the item with a value
            formBrowser.Document.All(thisArr(i,0)).Value = thisArr(i,1)
        end if
    next
end sub

' #3 Here are the subs handling the events of "formBrowser"
Private Sub formBrowser_DownloadComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles formBrowser.DownloadComplete
    thisTrd.Resume() 'start the thread again whenever the page has been downloaded completely
End Sub

Private Sub formBrowser_DownloadBegin(ByVal sender As Object, ByVal e As System.EventArgs) Handles formBrowser.DownloadBegin
    thisTrd.Sleep(100000) 'let the thread sleep whenever we begin download of a page, 100 seconds which should give us enough time to let the page load completely
End Sub

' #4 HERE goes the actual START of my little routine
    formBrowser.Navigate2("http://thisPage/thatForm.asp")
    Dim thisTrd = New Thread(AddressOf parseMyForm)
        thisTrd.IsBackground = True
        thisTrd.Start()

OK, here goes the problem...
The reason I want my thread/array-loop to _sleep_ while the page is loading is that whenever you try to handle items on the webpage that do not yet exists (ie are already loaded) the application will fail, returning errors - which is absolutely normal and correct...
THOUGH, when I set the thread ("thisTrd") to sleep on the event of a page being loaded by "formBrowser" - "formBrowser" _ALSO_ goes to sleep. Leaving me waiting for an error to happen as when the thread starts again still no page has been loaded. All of this could of course be handled by letting the formBrowser_downloadBegin set a public booleand ("pageLoaded") to false, formBrowser_downloadComplete set it to true and then letting a while loop check for "pageLoaded = true" but I really want to avoid unnecessary workload on the application.

So my question is, how do I avoid the formBrowser (AxWebBrowser) going to sleep? Or - how do I instance the formBrowser (which is visible and exists on my form in the application) as a thread of it's own?

MANY MANY MANY THANKS FOR A SOLUTION TO THIS ONE!!!
Peace,
Gemini
Avatar billede finger Nybegynder
28. juni 2004 - 09:11 #1
This sounds like you going over the river to get water....

Why oh why don't you just use the formBrowser_downloadComplete event for this??? it is made to be able to handle situations like this!
instead of setting a bool with the event, then just start and stop the thread that does the required work....
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester