Hi, I'm trying to find a way to make backgroundworker do what's in the webbrowser.
There is a time-consuming part in the webbrowserdocumentcompleted event that I want backgroundworker to tackle. Unfortunately, I don't know how to link that part to backgroundworker so that BW can do that job instead of webbrowser.
Here's what in the webbrowserdocumentcompleted event:
Sub WebBrowser1DocumentCompleted(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
If CheckBox1.Checked = True Then
'Create a new instance of the Decaptcher class
Dim decap As Decaptcher = New Decaptcher(TextBox3.Text, TextBox4.Text)
Dim strSource As String = ""
For Each Captcha As HtmlElement In WebBrowser1.Document.Images
If Captcha.GetAttribute("src").Contains("http://www.google.com/recaptcha/api/image?c=03AHJ") Then
strSource = Captcha.GetAttribute("src")
Exit For
End If
Next
'Downloads the image
Dim requestPic As WebRequest = WebRequest.Create(strSource)
Dim responsePic As WebResponse = requestPic.GetResponse()
Dim img As Image = Image.FromStream(responsePic.GetResponseStream())
Dim answer As String = decap.sendCaptcha(img)
Dim badCaptcha As Boolean = False
If badCaptcha = True Then
End If
WebBrowser1.Document.GetElementById("recaptcha_response_field").SetAttribute("value", answer)
For i As Integer = 0 To WebBrowser1.Document.All.Count - 1
If WebBrowser1.Document.All(i).GetAttribute("type").Contains("submit") Then
WebBrowser1.Document.All(i).InvokeMember("click")
End If
Next
End If
If CheckBox1.Checked = False Then
For Each Captcha As HtmlElement In WebBrowser1.Document.All
If Captcha.GetAttribute("src").Contains("http://www.google.com/recaptcha/api/image?c=03AHJ") Then
CaptchaForm.picBoxCaptchaImage.ImageLocation = Captcha.GetAttribute("src")
CaptchaForm.Show()
End If
Next
End If
End If
The time consuming part starts from line 2 to line 30. My program freezes whenever webbrowser tries to do this job, so I need BW to do this specific job instead. Any way to accomplish that?