i have s Sub() like this, to download HTML page using GeckoWebBrowser
wb1 = Nothing
wb1 = New Gecko.GeckoWebBrowser
wb1.Navigate(v_url)
totalticks = 0
loadtimer.Start()
Do
If m_stop = True Then Exit Do
If wb1.IsBusy = False Then 'wb1.ReadyState = WebBrowserReadyState.Complete Then
If IsNothing(wb1.Document) = False Then
If IsNothing(wb1.Document.Body) = False Then
Exit Do
End If
End If
ElseIf wb1.IsBusy = True And String.IsNullOrEmpty(sucessID) = False Then 'wb1.ReadyState = WebBrowserReadyState.Interactive And String.IsNullOrEmpty(sucessID) = False Then
If IsNothing(wb1.Document) = False Then
If IsNothing(wb1.Document.Body) = False Then
If InStr(wb1.Document.Body.InnerHtml, sucessID, CompareMethod.Text) <> 0 Then
Exit Do
End If
End If
End If
End If
If totalticks = 15 Then
'wb1.Dispose()
wb1.Stop() 'wb1 = New System.Windows.Forms.WebBrowser
wb1.Reload(Gecko.GeckoLoadFlags.IsRefresh)
'wb1.ScriptErrorsSuppressed = True
'wb1.Navigate(v_url)
ElseIf totalticks >= 30 Then
wb1.Stop()
Exit Do
End If
'FreeUpMemory()
Application.DoEvents()
Loop
My problem is that Application.DoEvents takes a long time to process and finish. P.S i am using STA thread to run this Sub()
Ok people here is how my problem was solved, and thanks for the others who tried to help! much appreciated. Ok here it goes:
Basically this 2 lines where in loop
So this for some reason was making the messages queue too crowded therfore the application.doevents was taking too long to process those messages. So all i did was decalring
wb1
as gloabl object (i.e.dim wb1 as New GeckoWebBrowser
) this way i didnt need to set it to nothing then initialize the object again. So anyway i removed the above 2 lines and used the instaniated object instead.Now things running so smooth and fast, even with DoEvents() !!! YAY!!