开第二贴共100分继续问,子线程下调用WebBrowser的问题

CrazyCode1981 CrazyCode1981 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
原帖地址: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 这些都无法取值
}
}

这个问题我百度了几天 貌似都无法解决....恭请请大神现身。
...全文
评论 8
收藏 已收藏
分享
返回顶部
CrazyCode1981
C# 111,129 成员 642,538 内容