1

I am trying to pass a webbrowser object to the background worker in order to parse the currently open page and create a report, but I cant seem to get it right.

I need to access the web elements normally accessed like so:

TagList = WebBrowser1.Document.GetElementsByTagName("TR")

I figured I could do:

wrkCollectItems.RunWorkerAsync(WebBrowser1)

In the "dowork" sub it looks like:

ImportWebPageData(e.argument)

with the following code running:

Private Sub ImportWebPageData(byval objWebArg as object)
    Dim TagList As HtmlElementCollection
    TagList = objWebArg.Document.GetElementsByTagName("TR") 'specified cast is not valid here
End Sub

How do I need to restructure my code in order to pass the object correctly in order to access it? Thanks

Jason Bayldon
  • 1,296
  • 6
  • 24
  • 41
  • 1
    That cannot work, the Document object is owned by the UI thread and is not thread-safe. The only alternative is to create the WebBrowser on another thread, shown in [this answer](http://stackoverflow.com/a/4271581/17034) – Hans Passant Aug 30 '13 at 14:23
  • @HansPassant Perhaps I could then just save a copy of the web page locally, and access it through background worker, passing the filepath string as an argument instead? Also, if you would like to provide that as an answer? – Jason Bayldon Aug 30 '13 at 23:12
  • You cannot copy the DOM. Pretty sure I already posted the answer, check the link again. – Hans Passant Aug 30 '13 at 23:44

0 Answers0