Visual Basic Development Bookmark and Share   
 Home > Visual Basic Language > Webbrowser control and threading
 

Webbrowser control and threading

I am trying to use a webbrowser control to retrieve some information from a couple of websites. ( Login, send some data, click some button... etc)
I've created subs for every site i need to login to (yahoo, bla.. bla)
Then when a button is clicked i called the functions like so:

Private
 Sub
 submit_btn_Click(ByVal
 sender As
 System.Object, ByVal
 e As
 System.EventArgs) Handles
 submit_btn.Click

       call
 SubNameHere
call SubName End Sub
Now what i need is a second button so I can pause or stop the current calls
I searched around and found threading to be perfect for what I need, but I can't get the browser to work.
I tried to change the button to:
Private Sub submit_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles submit_btn.Click

        Dim t As New Thread(AddressOf thr1)
        t.Start()
    End Sub
and thr1 as:
Private
 Sub
 thr1()
        Try

            Dim
 browser As
 New
 WebBrowser
            browser.ScriptErrorsSuppressed = True

            browser.Visible = True

            Timer2.Enabled = True

            results.Text = ""

            Call
 func1
            Call
 func2
        Catch
 ex As
 Exception
            MsgBox("Error: "
 & ex.Message)
        End
 Try

    End
 Sub

Sample of func1:
public sub func1()
browser.Navigate("some url")
browser.getelementbyid.... etc!
end sub
Any thoughts?
Proud tutorial creator for hackyourwindows.com :)
Gavro  Saturday, November 28, 2009 4:11 PM
Note that WebBrowser is like most Windows controls and expects to run on a single thread. Since it downloads in the background, this normally is not a problem. Not sure why you need to introduce multiple threads given the built-in background processing automatic to the WebBrowser.


BinaryCoder  Sunday, November 29, 2009 2:00 AM
Well.. actually i needed a way to control the process. You see, I have a sub created for every site i need to login and retrieve data. And that means like 40 subs. Now if my user wants to stop the process at any time, I really don't know how to do it.
Ideally what I need is a way to pause/stop the process at any time, and if possible to have a button for skipping current site. I thought the separate thread will do the job for the pause/stop part. Still no idea for the skip current website(sub)...
If someone can suggest a better approach... I'm open! Thanks!
Proud tutorial creator for hackyourwindows.com :)
Gavro  Sunday, November 29, 2009 7:15 AM
Latest update: after searching for 10 hr i found something, i think, but didn't try it though.
It seems I need to create a thread, then in that thread to ad a sub that invokes the thread with the webbrowser control... something like that... I'm confused... :(
Proud tutorial creator for hackyourwindows.com :)
Gavro  Sunday, November 29, 2009 10:38 AM
Let me step back and explain again:
I use Visual Basic.net to create a program that connects to several websites, logins, then post some data. I can't use the httpwebrequest, some java is required on those sites, so i use the webbrowser control.
Now I created a form, some fields for input data and a submit button. The coding part is like this:

Code:
sub website1(vars)
'login here
'post some data
'get some data back
'etc
end sub
So every site has its own sub.
Now the submit button calls all of these subs:

Code:
Private Sub submit_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles submit_btn.Click
call website1
call website2
End Sub
The problem is that I can't control what happens after submit button is clicked. I need to pause or stop the process at any time. If I exit the program while processing, I can see that even if the window disappear, the program is still running!
I tried to use a thread for this, but the subs only get called if I use begininvoke, or invoke on a starter thread... A real mess that I don't quite understand as a beginner.
Any thoughts are appreciated.

Proud tutorial creator for hackyourwindows.com :)
Gavro  Sunday, November 29, 2009 9:52 PM

You can use google to search for other answers

Custom Search

More Threads

• multiplying integer variables
• very nooby question
• My first program needs bigtime help!
• Encrypt A String
• lload database to combobox and draw line with the selection made by user
• Clean up file before import to DB
• Referencing DataTable
• ListBox Malfunction
• Regarding windows API waveInAddBuffer
• Package and Deployment - XLStart Up