WinForm WebBrowser Control is loading slowly. Best preload method?

We have a summary view in our winform application that uses the WebBrowser control to display summary information from a web page. We use this to get a rich tabular layout that we would not be able to accomplish using standard winform controls. when you first view the view on the client, it takes some time to deploy (running IE in the background, which I assume), and the application freezes for several seconds. I am considering some kind of preboot mechanism that runs IE in the background and would like some community tips.

I am considering launching off-screen or in an invisible form using a web browser control when starting the application or launching an IE instance in some kind of side stream when starting the application.

any suggestions?

+3
source share
2 answers

You can preload controls during application launch in a separate thread. Pay attention to the state of the STA apartment, which is mandatory if you want to manipulate some COM objects (for example, WebBrowser).

public static class ControlPreloader
{


    public static void PreloadAsync()
    {
        var thread = new Thread(Preload);
        thread.SetApartmentState(ApartmentState.STA);
        thread.Start();
    }

    private static void Preload()
    {
        using (var hostForm = new Form())
        {
            var control = new WebBrowser();
            hostForm.Controls.Add(control);
            control.CreateControl();

            hostForm.Close();
        }
    }

}
+3
source

, , , , about:blank. DocumentCompleted URL. , " IE", .

, , , " " , , WPF ( WinForms), .

+2

Source: https://habr.com/ru/post/1751040/


All Articles