Hi.
Due to the huge memory consumption of the component (or the Chrome engine), after an hour working my application consume all the available memory.
As I read in this forum the solution is to destroy the WebView and create again but when I try to do this the new WebView doesn't shows in the Form and doesn't works. After some hours I have two examples, one works and the other no, the problem is that I need the approach used in the one that doesn't works and I don't know what's going wrong with this example, so here we go with the code:
First a working example
Code: C#
public partial class Form1 : Form
{
#region Variables
private WebView _browser;
private IntPtr _handle;
private bool _completed = false;
#endregion
public Form1(string instanceId)
{
InitializeComponent();
EO.Base.Runtime.Exception += Runtime_Exception;
_handle = Handle;
CreateWebView();
}
public void DestroyView()
{
_browser.Dispose();
_browser = null;
Application.DoEvents();
CreateWebView();
}
public void CreateWebView()
{
_browser = new WebView();
_browser.LoadCompleted += _browser_LoadCompleted;
_browser.ZoomFactor = 0.35;
_browser.Url = "google.com";
_browser.Create(_handle);
}
private void _browser_LoadCompleted(object sender, LoadCompletedEventArgs e)
{
DestroyView();
CreateWebView();
}
private void Runtime_Exception(object sender, ExceptionEventArgs e)
{
Console.WriteLine(e);
}
}
In this example I only load google.com and when the loadCompled event arrives I destroy the WebView and create a new one, as you can see very simple.
Now the example that doesn't works
Code: C#
public partial class Form1 : Form
{
#region Variables
private WebView _browser;
private IntPtr _handle;
private bool _completed = false;
#endregion
public Form1(string instanceId)
{
InitializeComponent();
_handle = Handle;
CreateWebView();
new Thread(() => foo()).Start();
}
public void foo()
{
while (true) {
if (_completed) {
_completed = false;
Console.WriteLine("Creating the view again");
DestroyView();
CreateWebView();
}
Thread.Sleep(5000);
}
}
public void DestroyView()
{
_browser.Dispose();
_browser = null;
Application.DoEvents();
CreateWebView();
}
public void CreateWebView()
{
_browser = new WebView();
EO.Base.Runtime.Exception += Runtime_Exception;
_browser.LoadCompleted += _browser_LoadCompleted;
_browser.ZoomFactor = 0.35;
_browser.Url = "google.com";
_browser.Create(_handle);
}
private void _browser_LoadCompleted(object sender, LoadCompletedEventArgs e)
{
_completed = true;
}
private void Runtime_Exception(object sender, ExceptionEventArgs e)
{
Console.WriteLine(e);
}
}
In this case I create teh WebVIew in the same way but when loads set _complete = true, so the foo function must destroy the WebView and create another one, but in this case when the new WebView is created isn't visible and doesn't works.
Thanks in advance.