开第二贴共100分继续问,子线程下调用WebBrowser的问题
原帖地址:http://topic.csdn.net/u/20120911/23/6e855db4-6b7d-4790-a7e9-3a5eed076470.html
主窗体的代码:
WorkThread = new Thread(Start);
WorkThread.SetApartmentState(ApartmentState.STA);
WorkThread.Start();
private void Start()
{
for (int i = 0; i < BookList.Items.Count; i++)
{
string MarcIntroduction = BookList.Items[i].SubItems[4].Text.Trim();
HtmlM HM=new HtmlM(); HM.Html(MarcIntroduction);
}
}
HtmlM类代码
public bool Html(string BBe)
{
try
{
//省略部分无关代码
WebBrowserClass WBC = new WebBrowserClass();
WBC.StartWebBrowser(DetailsPageUrl);//** 使用WebBrowser控件方式获取Html }
catch (Exception ex)
{
MessageBox.Show(ex.Message + System.Reflection.MethodInfo.GetCurrentMethod().Name);
return false;
}
}
上面红字部分调用下面类
class WebBrowserClass
{
WebBrowser myWebPage = new WebBrowser();
System.Timers.Timer Monitor = new System.Timers.Timer();
public void StartWebBrowser(string Url)
{
Monitor.Interval = 3000;
Monitor.Elapsed += new System.Timers.ElapsedEventHandler(theout);
Monitor.Start();
myWebPage.ScrollBarsEnabled = true;
myWebPage.ScriptErrorsSuppressed = true;
myWebPage.Navigate("Url");
}
public void theout(object source, System.Timers.ElapsedEventArgs e)
{
if (myWebPage.IsBusy == false && myWebPage.StatusText == "完成")
{
MessageBox.Show("OK!");
Monitor.Stop();
//BookInfor.StaticClass.WebPageHtml = myWebPage.Document.Body.OuterHtml;
//BookInfor.StaticClass.flag = true;
}
每次断点到这里就假死半天 然后 myWebPage.IsBusy 这些都无法取值
}
}
这个问题我百度了几天 貌似都无法解决....恭请请大神现身。