Webbrowser is not disposing itself

社会主义新天地 提交于 2019-12-10 09:53:49

问题


I am creating a WPF application. I created a usercontrol and put a back button and webbrowser. The webbrowser is for showing some Flash objects and works without a problem. However, when I click back, the program returns to previous user control but I can still hear some sound coming from webbrowser. Here is my method:

void btnClose_Click(object sender, RoutedEventArgs e)
{
    Content contentPage = new Content();
    webBrowser1.Dispose();
    this.Content = contentPage;
}

How can I dispose webbrowser? Thanks in advance


回答1:


Instead of calling Dispose, you should reset the WebBrowser.Source property:

webBrowser1.Source = null;

MSDN doc of WebBrowser.Dispose says:

This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.



来源:https://stackoverflow.com/questions/9162240/webbrowser-is-not-disposing-itself

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!