從工作線程我打電話像UI線程:UI:調用該方法時發生錯誤。目標線程不再存在
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);
}
這個代碼是內螺紋,但我總是得到:
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:
錯誤是在這裏:
internal void InvokeIfRequired(Action a)
{
if (InvokeRequired)
Invoke(a); --> ERROR
else
a();
}
它工作2次(第一和第二瀏覽器)然後崩潰,因爲第一個線程關閉瀏覽器和2或3瀏覽器停止工作。
編輯:
在瀏覽器中加載頁面時,我呼籲後:
private void OnLoadEnd()
{
CefGlueBrowser.LoadEnd += (s, e) =>
{
MyCefStringVisitor visitor = new MyCefStringVisitor(this, m_url);
CefGlueBrowser.Browser.GetMainFrame().GetSource(visitor);
};
}
我該如何解決這個問題?我想要多線程的用戶界面瀏覽器...
無法找到InvokeIfRequired調用第一個代碼剪切 –
我該怎麼辦? – senzacionale
看起來像[這裏回答](http://stackoverflow.com/a/6362388/1015802)相同的場景。 – groverboy