using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;namespace 测试I
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(Open));
t.Start();
} private void Open()
{
wb.Navigate("http://baidu.com");
wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wbe_Auto);
} private void wbe_Auto(object sender, WebBrowserDocumentCompletedEventArgs e)
{
try
{
HtmlElement tmp = wb.Document.All["kw"]; wb.Document.All["subject"].SetAttribute("value", "aaaa");
}
catch (Exception ex)
{
txb.Text = ex.ToString();
}
} }
}System.InvalidCastException: 指定的转换无效。
在 System.Windows.Forms.UnsafeNativeMethods.IHTMLDocument2.GetLocation()
在 System.Windows.Forms.WebBrowser.get_Document()
在 测试I.Form1.wbe_Auto(Object sender, WebBrowserDocumentCompletedEventArgs e) 位置 d:\My Documents\Visual Studio 2005\Projects\测试I\测试I\Form1.cs:行号 36
请问如何在子线程中使用WebBrowser遍历HTML标记呢?
我今天下午试了
while(wb.IsBusy){Thread.Sleep(1000);}
似乎不行。