Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么web浏览器导航和加载时GUI会冻结?_C#_User Interface - Fatal编程技术网

C# 为什么web浏览器导航和加载时GUI会冻结?

C# 为什么web浏览器导航和加载时GUI会冻结?,c#,user-interface,C#,User Interface,当web浏览器导航和加载页面时,如何防止GUI冻结 webBrowser1.Navigate("http://www.costco.com/"); 例如,当它导航到该站点时,我的程序会稍微冻结,尤其是在加载网页时。我无法拖动和移动表单。无法单击选项卡控件中的选项卡按钮。我必须等待网页完全加载才能解冻 我注意到独立的Internet Explorer web浏览器没有这样的行为。加载网页时,它不会冻结 如何防止网页加载时UI冻结?根据我的经验,导航方法是一种非阻塞功能,不会释放UI 一个可能的原

当web浏览器导航和加载页面时,如何防止GUI冻结

webBrowser1.Navigate("http://www.costco.com/");
例如,当它导航到该站点时,我的程序会稍微冻结,尤其是在加载网页时。我无法拖动和移动表单。无法单击选项卡控件中的选项卡按钮。我必须等待网页完全加载才能解冻

我注意到独立的Internet Explorer web浏览器没有这样的行为。加载网页时,它不会冻结


如何防止网页加载时UI冻结?

根据我的经验,导航方法是一种非阻塞功能,不会释放UI

一个可能的原因是您在UI初始化之前调用它。。。加载表单后,必须调用此函数:

bool form_loaded=false;

private void Navigate(String url)
{
if(form_laded)
    webBrowser1.Navigate(url);
}

private void Form1_Load(object sender, EventArgs e)
{
        form_loaded = true
}
.
.
.
void boo() 
{
   Navigate ( "http://stackoverflow.com" );
}
`

如果要确保用户界面在导航过程中没有冻结,可以在每个
OnProgressChanged
事件中调用
DoEvents

private void webBrowser1_OnProgressChanged(WebBrowserProgressChangedEventArgs e)
{
    Application.DoEvents(); //update ui
}

当您在调用
导航
时,在代码中的哪个点?在按钮1下单击您是否尝试使用
异步/等待
?谢谢您的回答,但它不起作用。我通过添加另一个带有两个选项卡页的选项卡控件来测试您的代码。当boo()被执行时,我快速地用鼠标点击了tabpage1和TabPage2多次,但在大约1到2秒的时间内无法点击它们,因为在加载网页时,GUI在导航过程中会略微冻结。我认为问题在于您正在加载的网页。它是否加载了java或flash player之类的插件?(它们可能会导致类似的问题)使用
OnProgressChanged
没有帮助。冻结尤其是在页面等待大量Ajax请求时发生。