{"id":2653,"date":"2022-08-30T15:26:39","date_gmt":"2022-08-30T15:26:39","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/02\/04\/operating-a-runtime-webbrowser-control-from-a-background-thread-vb-net-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:26:39","modified_gmt":"2022-08-30T15:26:39","slug":"operating-a-runtime-webbrowser-control-from-a-background-thread-vb-net-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/operating-a-runtime-webbrowser-control-from-a-background-thread-vb-net-collection-of-common-programming-errors\/","title":{"rendered":"Operating a runtime webbrowser control from a background thread vb.net-Collection of common programming errors"},"content":{"rendered":"<p>The Control.InvokeRequired and Invoke members use the Handle property to figure out what thread owns the control. Problem is, the Handle is null for the web browsers that you created. A control only has a valid handle when you made it visible on a form. Which you didn&#8217;t do. It will then try to create the handle but that&#8217;s a fail whale, an ActiveX control like WebBrowser needs a valid Parent. Without Me.Control.Add(), as was done in your original version, it won&#8217;t have one.<\/p>\n<p>The workaround is simple, you just need another control with a valid Handle property. Any will do, it only cares about the thread that owns the handle, not the value of the handle.<\/p>\n<p>You have one: your form. Use <code>Me.InvokeRequired<\/code> and <code>Me.Invoke()<\/code> instead. Or Application.OpenForms(0) if you can&#8217;t easily get a reference to the form object, best avoided.<\/p>\n<p id=\"rop\"><small>Originally posted 2014-02-04 13:23:16. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>The Control.InvokeRequired and Invoke members use the Handle property to figure out what thread owns the control. Problem is, the Handle is null for the web browsers that you created. A control only has a valid handle when you made it visible on a form. Which you didn&#8217;t do. It will then try to create [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2653","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2653","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2653"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2653\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2653"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2653"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2653"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}