载入一个网页然后点一个按钮,对网页进行操作(点链接,填充表单,点按钮等)
private void button1_Click(object sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(d));//用线程操作
t.Start();
//d()//注释上面两行,用这行就是不用线程直接运行
}
private void (d)
{
webBrowser1.Document.GetElementById("id").InnerText = "myid".ToString().Trim();
}在按钮事件中,如果用线程操作,就会出错:
//////////////////////////////////////
未处理 System.InvalidCastException
Message="指定的转换无效。"
Source="System.Windows.Forms"
StackTrace:
在 System.Windows.Forms.UnsafeNativeMethods.IHTMLDocument2.GetLocation()
在 System.Windows.Forms.WebBrowser.get_Document()
在 Xiaonei_Helper.Form1.filll() 位置 E:\Documents\Visual Studio 2008\Projects\Xiaonei Helper\Xiaonei Helper\Form1.cs:行号 76
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
InnerException:
/////////////////////////////////////
这是什么原因啊?怎么解决?
我想要做的是用一个线程,控制网页,先载入,等载入完成后填写表单,自动登陆。
因为要等待网页载入,所以这个一定要线程,不然不行。。
但是在线程中却无法多webBrowser操作,只可以载入网页,但不可以点链接,填表单
好奇怪啊谁能帮我? 100分赠送
QQ:41709580
private void button1_Click(object sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(d));//用线程操作
t.Start();
//d()//注释上面两行,用这行就是不用线程直接运行
}
private void (d)
{
webBrowser1.Document.GetElementById("id").InnerText = "myid".ToString().Trim();
}在按钮事件中,如果用线程操作,就会出错:
//////////////////////////////////////
未处理 System.InvalidCastException
Message="指定的转换无效。"
Source="System.Windows.Forms"
StackTrace:
在 System.Windows.Forms.UnsafeNativeMethods.IHTMLDocument2.GetLocation()
在 System.Windows.Forms.WebBrowser.get_Document()
在 Xiaonei_Helper.Form1.filll() 位置 E:\Documents\Visual Studio 2008\Projects\Xiaonei Helper\Xiaonei Helper\Form1.cs:行号 76
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
InnerException:
/////////////////////////////////////
这是什么原因啊?怎么解决?
我想要做的是用一个线程,控制网页,先载入,等载入完成后填写表单,自动登陆。
因为要等待网页载入,所以这个一定要线程,不然不行。。
但是在线程中却无法多webBrowser操作,只可以载入网页,但不可以点链接,填表单
好奇怪啊谁能帮我? 100分赠送
QQ:41709580
{
Thread t = new Thread(new ThreadStart(d));//用线程操作
t.Start();
//d()//注释上面两行,用这行就是不用线程直接运行
}
private void (d)
{
webBrowser1.Document.GetElementById("id").InnerText = "myid".ToString().Trim();
}
============
能编译通过?
抱歉,这是笔误,源程序中不是 d,在写帖子的时候改成d,打错位置了应该是 d()
编译能通过,