简体   繁体   中英

WPF app with WebBrowser in WindowsFormsHost - very slow at loading website

I have a WindowsFormsHost that contains a WebBrowser control in a WPF app. My problem is that if I try to load a website for the first time it is doing it very slow. I also attempted to use the WPF WebBrowser, but it has the same issue. The problem is the same in a small sample app with just one WebBrowser & in a large one, so none of my functionality is affecting the load time. In Google Chrome, which I regularly use, I don't have this problem. Are any properties of the WebBrowser I should consider setting? Is this related to using the WebBrowser in a WPF app? Any suggestions are appreciated.

Thanks.

Simple sample app :

<Window x:Class="WebBrowserIntoWPFConceptTest.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="468" Width="840" xmlns:dxr="http://schemas.devexpress.com/winfx/2008/xaml/ribbon" xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars">
<Grid x:Name="grid">
    <Grid.ColumnDefinitions>
        <ColumnDefinition/>
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="80*"/>
        <RowDefinition Height="20*"/>
    </Grid.RowDefinitions>

    <!--<WebBrowser Grid.Row="0"
                Grid.Column="0"
                Grid.ColumnSpan="2"
                x:Name="wb"/>-->
    <Button Grid.Row="1" 
            Grid.Column="0"
            Width="50" 
            Height="50"
            VerticalAlignment="Bottom"
            Click="Button_Click"/>
    <Button Grid.Row="1"
            Grid.Column="1"
            Width="50" 
            Height="50" Click="Button_Click_1" />
</Grid>

namespace WebBrowserIntoWPFConceptTest

{ public partial class MainWindow : Window { private WindowsFormsHost winFormHost; System.Windows.Forms.WebBrowser wf_wb;

    public MainWindow()
    {
        InitializeComponent();
        wf_wb = new System.Windows.Forms.WebBrowser();
        winFormHost = new WindowsFormsHost();
        winFormHost.Child = wf_wb;
        Grid.SetColumn(winFormHost, 0);
        Grid.SetRow(winFormHost, 0);
        Grid.SetColumnSpan(winFormHost, 2);
        grid.Children.Add(winFormHost);
    }



    private void Button_Click(object sender, RoutedEventArgs e)
    {
        Uri uri = new Uri("http://www.google.com");
        wf_wb.Navigate(uri);
    }

    private void Button_Click_1(object sender, RoutedEventArgs e)
    {
        HtmlDocument htmlDoc = (HtmlDocument)wf_wb.Document;
    }
}

}

WebBrowser is wrapper of IE. So if you try IE and it is slow, then the WebBrowser is gonna be slow too. It could be some kind of virus that's making it slow. So scan your computer with virusscanner.

I have not heard about such problem. However I've had browser problems myself(in IE and mozilla) where page just didn't load and running virus scans fixed it finally.

If that didn't help, check ouf CefSharp project https://github.com/chillitom/CefSharp I would tell you to use that, because it's more "WPF'"ish. It allows you to do everything with WebBrowser.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM