I'm using background worker to manipulate some of the elements on my WebBrowser using vb.net.
For example the background worker RFIDReader
will check if I'm on a specific link.
ElseIf TerminalBrowser.Url.ToString.Contains(baseUrl + "box-office/ticket-verification") And rf_code <> "" Then
' Insert RF Code in "rf_code" hidden text field
Me.Invoke(Sub() Me.TerminalBrowser.Document.GetElementById("rf_code").SetAttribute("value", rf_code.ToLower))
End If
What happens here is, if I tap my RFID card. It will include that corresponding value to my rf_code
element in my browser.
Now what I want to happen is, I want to check if the container itself (synchronize-rfid
) does exist (Since it's a pop up). See image for reference.
Here's our code for that.
If Me.TerminalBrowser.Document.GetElementById("synchronize-rfid") IsNot Nothing Then
' Code here
end if
Reference: https://stackoverflow.com/a/2022120/1699388
The problem is, BackgroundWorker does not really interacts with UI as per the code above.
Is there any method for me to determine if that element exist using background worker?
I think I've done this and it does not work though.
Dim synchronize_rfid = Me.Invoke(Sub() Me.TerminalBrowser.Document.GetElementById("synchronize-rfid"))
If synchronize_rfid IsNot Nothing Then
' Code here
end if
Try declaring the variable first, then set it during the invocation (which will set it from the main thread).
The Sub()
lambda behaves like a normal Sub()
-End Sub
method, which means you can do the same things in there as if you had a separate method.
This works for me:
Dim synchronize_rfid As HtmlElement
If Me.InvokeRequired = True Then
Me.Invoke(Sub() synchronize_rfid = Me.TerminalBrowser.Document.GetElementById("synchronize-rfid"))
Else
synchronize_rfid = Me.TerminalBrowser.Document.GetElementById("synchronize-rfid")
End If
If synchronize_rfid IsNot Nothing Then
' Code here
End If
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With