Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have the following problem:

The downloadcomplete event is not loaded in the sub.

Unless I insert a Messagebox.Show as a test. Then the downloadcomplete event is triggered. I do not understand the problem.

Button calls thread with:

VB
Dim ThreadX As New Thread(AddressOf MTX)
ThreadX.SetApartmentState(ApartmentState.STA)
ThreadX.Start()


The web browser element is created in a new thread: (Works with Messagebox "MessageBox.Show("OK1")". Without dont work)


VB
    Sub MTX()
        Dim WB1 As New WebBrowser
        WB1.ScriptErrorsSuppressed = True
        WB1.Navigate(New Uri("https://google.at"))

Reload:
        MessageBox.Show("OK1")
        If WB1.ReadyState = WebBrowserReadyState.Complete Then
            MessageBox.Show("LOADED")
        Else
            Thread.Sleep(500)
            GoTo Reload
        End If

    End Sub



I have also tried it with a Do While Loop, without success

Any ideas? i Search since 2 days over 10 hours

What I have tried:

I have also tried it with a Do While Loop, without success

Any ideas? i Search since 2 days over 10 hours
Posted
Comments

1 solution

You cannot put the web browser control on a separate thread. It must be on the startup (UI thread) of the app in order to work.
 
Share this answer
 
Comments
ThomasVB 25-Dec-23 14:39pm    
It works if after Reload: the MessageBox -> MessageBox.Show("OK1") is stored. If the message box is not present, it does not work. So basically it should work. The web browser element only exists in the new thread. I do not have a GUI Web Browser element in use.
Dave Kreskowiak 25-Dec-23 15:20pm    
Yeah, so? It's still not going to work.

The next question is why are you even doing this?
ThomasVB 25-Dec-23 16:13pm    
Several thousand queries are executed in loops. Using the normal web browser element, the tool hangs or becomes slow. Download string does not work with what I am doing. It only works via the web browser element, and only in a separate thread. As I said: It works, but only if the message box is in front of it. Then it works without errors with the Downloadcomplete function.
Dave Kreskowiak 26-Dec-23 0:32am    
I don't care what you're doing with the MessageBox function. The WebBrowser control does not work reliably if you create it from the non-UI thread.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900