5

I have a C# .NET 3.5 application with an embedded web browser. The browser is designed to point to remote sites (Rather than anything local). Everything works fine, but when the page is slow to respond this causes my entire application to become unresponsive until the page is loaded.

I don't mind the browser being unresponsive while it does its thing, but the application going too is far from ideal.

Is there a good way to prevent this? Would it be beneficial to run the WebBrowser on a seperate thread - that's a bit beyond my skillset right now and I don't think the WebBrowser control really likes multithreading? But I can learn if needs be.

Dan
  • 1,958
  • 1
  • 18
  • 26
  • Have you checked your error log? There might be a clue to why your application becomes unresponsive. It is hard to diagnose you problem with so little information. – Eric Jun 11 '12 at 13:41
  • @autumyst I don't believe there is any issue as such. It only hangs briefly while the slow website loads. When this happens, Windows 7 (For example) gives the user the option To Wait or to the end the task which doesn't look great. – Dan Jun 11 '12 at 13:43
  • An important question--why are you using the WebBrowser control? What are you trying to do? It is a very cumbersome control, and depending on your needs, there might be a better way. – riwalk Jun 11 '12 at 13:44
  • @Stargazer712 It's part of an internal application. I need the user to be able to browse to an external dynamic website from within the application. To be honest, it's pretty ideal apart from this brief hanging. – Dan Jun 11 '12 at 13:47
  • Could you post the part of code that causes application to freeze? Also the code from [this answer](http://stackoverflow.com/a/4271581/625594) might be relevant for your case - it shows one of the methods for invokation of `WebBrowser.Navigate` in asynchronous way. – Sergey Kudriavtsev Jun 11 '12 at 13:53
  • Much of the WebBrowser API is already asynchronous by design. Do you have anything listening to the events (Navigating, Navigated, DocumentComplete, DownloadBegin/Complete, etc.)? – villecoder Jun 11 '12 at 13:54
  • @SergeyKudriavtsev It's just normal webBrowser1.Navigate(url) which causes the hang, until the page is loaded. – Dan Jun 11 '12 at 14:01

3 Answers3

2

See the answer #2 on this question for a solution on how to run it on a separate thread: BackgroundWorker and WebBrowser Control

You might as well read answer #1 too, it explain the behaviors you are seeing (WebBrowser control blocking UI thead).

Community
  • 1
  • 1
Jf Beaulac
  • 5,206
  • 1
  • 25
  • 46
  • Accepting because this is the right answer although I didn't need to use it in the end – Dan Jun 12 '12 at 11:23
0

As it happens I found that the root cause of this was my application running as administrator. Exactly the same issue was seen when using Internet Explorer - as such, I've simply rewritten the bits that required admin privileges so I'm now no longer seeing the original issue.

Dan
  • 1,958
  • 1
  • 18
  • 26
0

this happened only on win7;I use fiddler2 to Monitor HTTP/HTTPs traffic .I find embedded web browser to visit this web:http://ctldl.windowsupdate.com/msdownload/update/v3/static/trustedr/en/disallowedcertstl.cab?50ff94e72ac1a75c;the solution is follow:http://support.microsoft.com/kb/2730040/en (Method 2 or Method 3).you can try it.other u can use .net framework4.0,then u haven't this problem.

shine
  • 1