I don't want to get in trouble for posting Genesys code samples here, so I will just paste some code. This code can be added to the IWS sample Genesyslab.Desktop.Modules.InteractionExtensionSample.MySample pretty easily.
It at least demonstrates what needs to be done to avoid to memory leak in .net 3.5 (IWS 8.1.x). As ridiculous as it sounds, navigating to about:blank prior to disposing of the WebBrowser control is what we needed to do in order to avoid massive memory leaks with the control.
I just did some copy/paste and additions, so hopefully there are no typos!
In MySampleView.xaml, make the entire UserControl tag contain only this DockPanel control:
[code]
<!-- blank dockpanel where our WebBrowser control will be added -->
<DockPanel x:Name="dockPanelWebBrowser" DockPanel.Dock="Top" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
</DockPanel>
[/code]
In MySampleView.cs, add some new variables:
[code]
// create a WebBrowser object
private WebBrowser webBrowser;
// flag indicating if web browser control has been navigated to blank - should navigate to blank when destroying control
// to help minimize memory leaks
private bool isWebBrowserNavigatedToBlank = false;
[/code]
Add some code to the end of the constructor to instantiate the WebBrowser control and add it to the DockPanel
[code]
// instantiate new WebBrowser when constructor is run
webBrowser = new WebBrowser();
// add web browser to our dock panel
dockPanelWebBrowser.Children.Add(webBrowser);
// navigate somewhere, get this from a service call, attached data, textbox, whatever
NavigateToURL(webBrowser, "http://www.google.com");
[/code]
Inside the Destroy() method, add the following code. This is important to avoid memory leaks. It will force the WebBrowser control to navigate to about:blank prior to the view being destroyed:
[code]
try
{
if (!isWebBrowserNavigatedToBlank)
{
webBrowser.Navigated += NavigatedToAboutBlank;
NavigateToURL(webBrowser, "about:blank");
return;
}
webBrowser.Navigated -= NavigatedToAboutBlank;
webBrowser.Dispose();
webBrowser = null;
}
catch (Exception)
{
}
[/code]
Add event code for NavigatedToAboutBlank:
[code]
private void NavigatedToAboutBlank(object sender, NavigationEventArgs e)
{
isWebBrowserNavigatedToBlank = true;
this.Destroy();
}
[/code]
Add a method to do all our navigation for us:
[code]
private void NavigateToURL(WebBrowser webBrowser, String url)
{
try
{
webBrowser.Navigate(new Uri(url));
}
catch (Exception)
{
}
}
[/code]