Found almost everything to work with this component, except for one thing - how can I create an instance of an object in the background thread?

If you create like this:

WebControl browser = new WebControl(); browser.Source = new Uri("http://wtfismyip.com/text"); 

then does not want to send requests (or accept the answer, and did not understand). No exceptions, just browser.HTML is empty.

It works only like this:

 WebControl browser = new WebControl(); Controls.Add(browser); browser.Source = new Uri("http://wtfismyip.com/text"); 

but then you need to break into the UI stream.

All would be fine if they need 2 or 3, but the execution of such code here:

 for (int i = 0; i < 50; i++) { browsers[i] = new WebControl(); webPreferences[i] = new WebPreferences(true); webSessionProvider[i] = new WebSessionProvider(); webPreferences[i].ProxyConfig = proxy[i]; webSessionProvider[i].Preferences = new WebSessionProvider(); webSessionProvider[i].Views.Add(browsers[i]); Controls.Add(browsers[i]); } 

can freeze the form for 30-60s (did not measure it exactly, but Windows manages to mark the application as "not responding"). How can I create and use this component completely in the background thread?

To have something like:

 private async Task Do() { for (int i = 0; i < 9; i++) { browsers[i] = new WebControl(); webPreferences[i] = new WebPreferences(true); webSessionProvider[i] = new WebSessionProvider(); webPreferences[i].ProxyConfig = proxy[i]; webSessionProvider[i].Preferences = webPreferences[i]; webSessionProvider[i].Views.Add(browsers[i]); browsers[i].Source = new Uri("http://wtfismyip.com/text"); while (browsers[i].IsLoading) { await Task.Delay(500); } } } 
  • The UI component is unlikely to be used in a non-UI stream. Why do you forgive 50 browsers? - VladD
  • Self-made submitter. :) I would put everything on a geth / post, but through the browser it is much simpler and more effective in terms of emulation. That is, it can not be used at all without UI? And you can create, for example, 50 hidden forms with a browser, but so that the main form is free and does not freeze? - Andrei Tsapenko
  • In any case, everything goes through the UI stream, the problem is not whether the form is visible or not. You can, of course, create 50 UI threads, but I'm not sure that this will not slow down either. In any case, it is to unload the main UI. - VladD

1 answer 1

Found a solution, maybe someone will be interested. I could not open the Awesomium documentation, they have something with the site there, but I was able to bypass it and read it all the same. As a result, you can use not WebControl control, but WebView. The final code will look like this:

  WebSession s = WebCore.CreateWebSession( new WebPreferences() { ProxyConfig = "127.0.0.1:900" } ); WebView vw = WebCore.CreateWebView(1024, 768, s); vw.Source = new Uri("http://wtfismyip.com"); while (!vw.IsDocumentReady && vw.HTML == "" && vw.IsLoading)// Тут поставил много проверок, так как одна иногда не срабатывает. { WebCore.Update();// VS ругается и говорит, что метод уже устарел, но он работает. } 

Regarding WebCore.Update () - there is a Run () method in the documentation, but I have not figured out how it works, if there is information on how to use it - I will be happy with the description.

And yet, there are oddities when using async - if you do this:

  private async Task Do() { WebSession s = WebCore.CreateWebSession( new WebPreferences() { ProxyConfig = "127.0.0.1:900" } ); WebView vw = WebCore.CreateWebView(1024, 768, s); vw.Source = new Uri("http://wtfismyip.com"); while (!vw.IsDocumentReady && vw.HTML == "" && vw.IsLoading)// Тут поставил много проверок, так как одна иногда не срабатывает. { WebCore.Update();// VS ругается и говорит, что метод уже устарел, но он работает. } } 

then the UI thread is busy, but if you work through the Backgroundworker, then everything is fine. Any thoughts on this would be interesting.