【发布时间】:2011-05-01 13:59:31
【问题描述】:
我使用 WebBrowser 控件导航到 WordPress 博客的登录页面。 该页面加载正常,但每当我尝试从线程访问 WebBrowser 时。我得到一个特定的演员表是无效的例外。同样在调试时,一切都会冻结大约 5 秒。调试时,我尝试访问控件。我的所有成员变量都出现超时错误。
//in constructor of main form
Thread.CurrentThread.ApartmentState = ApartmentState.STA;
this.CheckForIllegalCrossThreadCalls = false;
mainThreadHandle = new Thread(mainThread);
mainThreadHandle.Start();
private void mainThread()
{
wbMain.Navigate("http://example.com/");
//navigating is set to false in the document complete event.
navigating = true;
while (navigating == true)
Thread.Sleep(5000);
try
{
//Where I get the issues
MessageBox.Show(wbMain.DocumentText);
}
catch (Exception e)
{
}
Thread.Sleep(1000);
}
【问题讨论】:
-
你能把
Specified cast is not valid异常的代码贴出来吗? -
您的代码中有错误。您需要查看您的代码并找到错误。
-
代码冻结 5 秒,因为您将其发送到睡眠 5000 毫秒。
-
@Shadow Wizard 我说的是冻结,而不是睡眠。我知道区别。每当我尝试访问控件本身时,它都会冻结大约 5 秒钟。我的整个 IDE 冻结了。
-
如果你移除睡眠,它仍然会冻结吗?
标签: c# .net winforms webbrowser-control