From the Worker thread I am calling UI thread like:
using(CefGlueBrowserForm cefGlueBrowserForm = new CefGlueBrowserForm(propertyBag.ResponseUri.ToString()))
{
CefGlueBrowserForm cefGlueBrowserForm = new CefGlueBrowserForm(propertyBag.ResponseUri.ToString());
cefGlueBrowserForm.Show();
while (!cefGlueBrowserForm.Done)
{
Application.DoEvents();
}
propertyBag.GetResponse = () => new MemoryStream(Encoding.UTF8.GetBytes(cefGlueBrowserForm.DocumentDomHtml));
base.Process(name, propertyBag);
}
and this code is inside thread, but I always get:
System.ComponentModel.InvalidAsynchronousStateException was unhandled
HResult=-2147024809
Message=An error occurred invoking the method. The destination thread no longer exists.
Source=System.Windows.Forms
StackTrace:
at System.Windows.Forms.Control.WaitForWaitHandle(WaitHandle waitHandle)
at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
at System.Windows.Forms.Control.Invoke(Delegate method)
at Xilium.CefGlue.WindowsForms.CefWebBrowser.InvokeIfRequired(Action a)
at Xilium.CefGlue.WindowsForms.CefWebLoadHandler.OnLoadStart(CefBrowser browser, CefFrame frame)
at Xilium.CefGlue.CefLoadHandler.on_load_start(cef_load_handler_t* self, cef_browser_t* browser, cef_frame_t* frame)
InnerException:
Error is here:
internal void InvokeIfRequired(Action a)
{
if (InvokeRequired)
Invoke(a); --> ERROR
else
a();
}
It works 2 times (first and second browser) then crash, because first thread close the browser and 2 or 3 browser stop working.
EDIT:
After page in browser is loaded I am calling:
private void OnLoadEnd()
{
CefGlueBrowser.LoadEnd += (s, e) =>
{
MyCefStringVisitor visitor = new MyCefStringVisitor(this, m_url);
CefGlueBrowser.Browser.GetMainFrame().GetSource(visitor);
};
}
How can I solve this? I want to have multithread UI browsers...