0

I have button and tabcontrol having some tabs on my form. There is webbrowser-control on the second tab. I use a backgroundworker for creating its page. String:

bw.DoWork += new DoWorkEventHandler((s, e) => { webBrowser.DocumentText = "qwerty"; });

is in form constructor after InitializeComponent() and just one string:

bw.RunWorkerAsync();

in button click handler. After the run my application on pressing the button I get "Unable to get the window handle for the 'WebBrowser' control. Windowless ActiveX controls are not supported." But it works correct if I choose the second tab (having webbrowser) before. How can I solve this problem?

SerG
  • 1,251
  • 4
  • 18
  • 37
  • Have you tried [this](http://stackoverflow.com/questions/4269800/webbrowser-control-in-a-new-thread/4271581#4271581)? – Jordy Jul 08 '13 at 12:08
  • @Jordy I need use exactly backgroundworker, but it looks like I have solved the problem already. – SerG Jul 08 '13 at 12:16

1 Answers1

0

Keeping all calls of user interface methods on the same thread solves this problem. DoWorkEventHandler runs in another thread, but RunWorkerCompletedEventHandler runs in the same thread, so if I put into DoWorkEventHandler only getting the data (forming of webpage) and move setting it to webBrowserAstrHost.DocumentText propetry to RunWorkerCompletedEventHandler, everything works correctly.

SerG
  • 1,251
  • 4
  • 18
  • 37